当jtable打开单元格弹出窗口,然后单击其他单元格,如何使单击的单元格请求焦点?

时间:2022-04-24 02:18:23

I have write java swing JTable, in the table, a cell like JComboBox, when I edit the JComboBox cell, it open the item list, then I clicked the other cell(JTextField),how to make the clicked cell request focus in the table? Now I need double click the JTextField cell, then it can grab the focus.

我已经编写了java swing JTable,在表中,像JComboBox这样的单元格,当我编辑JComboBox单元格时,它打开项目列表,然后我点击其他单元格(JTextField),如何使单击的单元格请求焦点在表格中?现在我需要双击JTextField单元格,然后它可以抓住焦点。

1 个解决方案

#1


0  

I got what you are facing.

我得到了你所面对的。

Use method ClickCountToStart to enable editing in single click to the JTextfield which is inside the tablecell. here is an example , about how you can use it

使用方法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);
    } 

#1


0  

I got what you are facing.

我得到了你所面对的。

Use method ClickCountToStart to enable editing in single click to the JTextfield which is inside the tablecell. here is an example , about how you can use it

使用方法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);
    }