我在JTextArea
中有一个JDialog
。 JDialog
使用GridLayout
。
我想在JTextArea
的每一行上使用7位数字(每行将是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);
答案 0 :(得分:0)
我提出了另一种满足我要求的解决方案。我使用select p.id, p.name
from (
select 'Alice' as name from dual
union all select 'Bob' from dual
union all select 'Alice' from dual
) searched s
join people p on p.name = s.name;
来检查每行是否包含7位数字(MATRICULE_REGEX
),而不是到达7个字符时换行。如果没有,我将拒绝1\\d{6}
内容。
JTextArea