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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.