JTable setRowSelectionInterval对JButton没有影响。

时间:2021-08-22 11:34:16

Using a JTable, my Table Model setValueAt() method moves the selection to the next row in certain cases, using setRowSelectionInterval() and setColumnSelectionInterval(). When it's called from the (default) cell editor (by user typing in the cell and hitting tab), the code works: the desired next cell is selected (the first one on the next row).

使用JTable,我的表模型setValueAt()方法使用setRowSelectionInterval()和setColumnSelectionInterval()将选择移动到特定情况下的下一行。当它从(默认)单元编辑器(由用户在单元格中输入并按tab)调用时,代码会工作:选择下一个单元格(下一行的第一个单元格)。

However, if the user uses Return rather than Tab to commit the edit, the selection doesn't happen; instead the cell below is selected. That's fine with me.

但是,如果用户使用Return而不是Tab来提交编辑,则不会发生选择;而是选择下面的单元格。跟我没关系。

I also have a JButton to clear a row. The button's action function calls the model's setValueAt() function for the desired cells. Unfortunately, the setRowSelectionInterval() and setColumnSelectionInterval() methods have no apparent effect; instead, no cells are selected.

我还有一个JButton来清除一行。按钮的动作函数调用模型的setValueAt()函数来获得所需的单元格。不幸的是,setRowSelectionInterval()和setColumnSelectionInterval()方法没有明显的效果;相反,没有选择单元格。

I've tried table.requestFocusInWindow() and table.getParent().requestFocusInWindow(), as well as table.changeSelection(row, 0, false, false), all to no apparent effect.

我已经尝试了table.requestFocusInWindow()和table.getParent(). requestfocusinwindow()和表。变更选举(行,0,假,假),均无明显效果。

Is there anything basic I'm missing here, before I go to the trouble of building the SSCCE?

在我去建造SSCCE的麻烦之前,这里有什么基本的东西吗?

In case it matters, here's the container hierarchy:

如果它很重要,下面是容器层次结构:

parent JPanel
  button rows JPanel
    button row 1 JPanel
    button row 2 JPanel
  table JScrollpane
    JTable

The button in question is in button row 1.

问题的按钮在按钮第1行。

Thanks!

谢谢!

1 个解决方案

#1


4  

Maybe you can use the Table Cell Listener to listen for edits to the table. It listens for actual changes done by the JTable editor.

也许您可以使用这个表池侦听器侦听表的编辑。它侦听JTable编辑器所做的实际更改。

Then in the supplied Action you can select the appropriate row. You may need to wrap the Action code in a SwingUtilities.invokeLater(...) to make sure the code executes after the table is completely finished editing.

然后在提供的操作中,您可以选择适当的行。您可能需要将操作代码包装在swinguse . invokelater(…)中,以确保在表完成编辑后执行代码。

#1


4  

Maybe you can use the Table Cell Listener to listen for edits to the table. It listens for actual changes done by the JTable editor.

也许您可以使用这个表池侦听器侦听表的编辑。它侦听JTable编辑器所做的实际更改。

Then in the supplied Action you can select the appropriate row. You may need to wrap the Action code in a SwingUtilities.invokeLater(...) to make sure the code executes after the table is completely finished editing.

然后在提供的操作中,您可以选择适当的行。您可能需要将操作代码包装在swinguse . invokelater(…)中,以确保在表完成编辑后执行代码。