[英]Adding a row to a jTable on downarrow at bottom
I have a jTable which currently displays and allows editing of a database table, I am now trying to sort adding tuples. 我有一个jTable当前显示并允许编辑数据库表,我现在尝试对添加元组进行排序。
I am trying to get it to automatically add a row on downarrow at the bottom. 我正在尝试使其自动在底部的downarrow上添加一行。 So if I am at the bottom on the table and click my down arrow a new row will appear below.
因此,如果我在桌子的底部,然后单击我的向下箭头,则会在下面显示新行。 I just can't figure out how to do it.
我只是不知道该怎么做。
Thanks James 谢谢詹姆斯
Action handling of JTable
happens in javax.swing.plaf.basic.BasicTableUI
. JTable
动作处理发生在javax.swing.plaf.basic.BasicTableUI
。 In your case, you probably need to register a new action for SCROLL_DOWN_CHANGE_SELECTION
. 就您而言,您可能需要为
SCROLL_DOWN_CHANGE_SELECTION
注册一个新动作。 In the action, check whether the current selection == last row of the table. 在操作中,检查当前选择是否==表的最后一行。
If that doesn't work, set a breakpoint in javax.swing.plaf.basic.BasicTableUI.Actions.actionPerformed(ActionEvent)
to see which action is really executed. 如果这不起作用,请在
javax.swing.plaf.basic.BasicTableUI.Actions.actionPerformed(ActionEvent)
设置一个断点,以查看实际执行了哪个动作。
JTable has a default Action for the down arrow key. JTable的向下箭头键具有默认的Action。 If you want to change this behaviour then you need to create a custom Action.
如果要更改此行为,则需要创建一个自定义动作。 You can do this easily by using the Wrapping Actions concept to leverage the default code.
您可以通过使用“ 包装动作”概念来利用默认代码来轻松实现此目的。
You can also look at Table Tabbing for a working example of wrapping an Action. 您也可以在表格标签中查看包装动作的工作示例。 You code for the Action would be much simpler and would be something like:
您为该操作编写的代码将更加简单,并且类似于:
if (last row is selected)
add a new row to the table
invoke the default down arrow action
You'll need to create a KeyListener and add this to your table: 您需要创建一个KeyListener并将其添加到表中:
public void keyReleased(KeyEvent e) {
int keyCode = e.getKeyCode();
if (keyCode == KeyEvent.VK_DOWN)
// check if selected table row = last row and if so: add new row to table model
}
greetz, 格尔茨,
Stijn 斯泰恩
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.