限制每个 JTextArea 行上的字符数

我有JTextArea一个JDialog. JDialog使用一个GridLayout.


我想在每行上有 7 位数字JTextArea(每行将是 7 个int注册号)。出于用户体验的原因,我希望在JTextArea一行达到 7 个字符时添加新行或停止扩展。


不起作用的事情: - 在JTextArea构造函数中指定列数-matriculesText.setLineWrap(true);和matriculesText.setWrapStyleWord(true);


我担心uploadDialogManager.setHgap(20);可能会破坏密码。我想知道是否JDialog应该有一个固定的大小。


这就是我构建我的方式JDialog:


// initialization

    Dialog uploadParent = null;

    JDialog uploadDialog = new JDialog(uploadParent);

    GridLayout uploadDialogManager = new GridLayout(UPLOAD_DIALOG_ROWS, 

UPLOAD_DIALOG_COLUMNS);


    // uploadDialog properties

    uploadDialog.setSize(new Dimension(UPLOAD_DIALOG_WIDTH, UPLOAD_DIALOG_HEIGHT));

    uploadDialog.setLayout(uploadDialogManager);

    uploadDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);


    //Set up the horizontal gap value

    uploadDialogManager.setHgap(20);

    //Set up the vertical gap value

    uploadDialogManager.setVgap(20);

    //Set up the layout of the buttons

    //uploadDialogManager.layoutContainer();


    // components initialization

    JLabel exerciceLabel = new JLabel("exercice number : ");

    JComboBox<Integer> exerciceNumbers = new JComboBox<Integer> 

  (EXERCICE_NUMBERS);

    JLabel matriculeLabel = new JLabel("please enter your matricules, one per 

  line : ");

    JTextArea matriculesText = new JTextArea(1, 1);

    JButton confirm = new JButton("confirm");

    JButton cancel = new JButton("cancel");


    matriculesText.setLineWrap(true);

    matriculesText.setWrapStyleWord(true);



12345678_0001
浏览 308回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java