首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >限制每行JTextArea上的字符数

问限制每行JTextArea上的字符数
EN

Stack Overflow用户
提问于 2018-07-18 06:25:09
回答 0查看 70关注 0票数 1

我在JDialog中有一个JTextArea。JDialog使用GridLayout。

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

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

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

下面是我构建JDialog的方式:

代码语言:javascript
复制
// 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);
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51390982

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档