JTable如何在行之间添加行 [英] JTable How to add a row between rows
问题描述
我以前一直在寻找这个问题,我找不到任何关于这个或主题的问题,我假设它可能是不可能做到的,虽然这看起来很奇怪,因为这个功能很有用。 / p>
我想在这种情况下,我说3行,添加另一个不在最后,但在第1行之后。这有可能吗?
请不要提及基于某些ID的行安排,因为这是我在我的情况下要做的最后一件事。
使用 DefaultTableModel
< - 查看docs more contructors
DefaultTableModel model = new DefualtTableModel(String colNames,int rows);
JTable table = new JTable(model);
然后您可以使用以下方法之一
-
DefaultTableModel#insertRow(int row,Object [] rowData)
- 在模型的行中插入一行。除非指定了rowData,否则新行将包含空值。将生成正在添加的行的通知。
或
-
DefaultTableModel#insertRow(int row,Vector rowData)
- 在模型的行中插入一行。除非指定了rowData,否则新行将包含空值。将生成正在添加的行的通知。
I've been looking for this quite a long time before and I can't find any question about this nor topic, I am assuming it might be impossible to do, though it seems odd as the feature would be useful.
I would like in the situation when I have let's say 3 rows, to add another one not at the end, but after row number 1. Is that possible in any way?
Please do not mention row arranging based on some id, as that is the last thing I would do in my situation.
Use a DefaultTableModel
<- see docs more contructors
DefaultTableModel model = new DefualtTableModel(String colNames, int rows);
JTable table = new JTable(model);
Then you can use one of the following methods
DefaultTableModel#insertRow(int row, Object[] rowData)
- Inserts a row at row in the model. The new row will contain null values unless rowData is specified. Notification of the row being added will be generated.
Or
DefaultTableModel#insertRow(int row, Vector rowData)
- Inserts a row at row in the model. The new row will contain null values unless rowData is specified. Notification of the row being added will be generated.
这篇关于JTable如何在行之间添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!