【问题标题】:when jtable open cell popup, then click the other cell,how to make the clicked cell request focus?当jtable打开单元格弹出时,然后单击另一个单元格,如何使单击的单元格请求焦点?
【发布时间】:2013-10-29 00:55:47
【问题描述】:
我写了java swing JTable,在表格中,像JComboBox这样的单元格,当我编辑JComboBox单元格时,它打开项目列表,然后我点击了另一个单元格(JTextField),如何使点击的单元格请求焦点在表中?现在我需要双击 JTextField 单元格,然后它才能抓住焦点。
【问题讨论】:
标签:
java
swing
popup
jtable
jcombobox
【解决方案1】:
我知道你所面临的。
使用ClickCountToStart 方法可以单击编辑表格单元格内的JTextfield。
这是一个例子,关于你如何使用它
DefaultCellEditor onSingleClick = new DefaultCellEditor(new JTextField());
onSingleClick.setClickCountToStart(1);
//set the editor to the every column
for (int i = 0; i < table.getColumnCount(); i++) {
table.setDefaultEditor(table.getColumnClass(i),onSingleClick);
}