Removing unused Rows from jTable

2019-08-03 16:57发布

How do I remove unused rows from a JTable?

I first create a table of a fixed size in a JPanel and then fill elements as needed.

Now I don't want unused rows to be displayed in my table. Please help.

2条回答
我想做一个坏孩纸
2楼-- · 2019-08-03 17:24

DefaultTableModel has a method removeRow which removes a row from the table. Pass the row index which you want to remove from the table.

Now I don't want unused rows to be displayed in my table.

This I am not sure please post an SSCCE to show us what is the flag that says these rows are not used.

查看更多
混吃等死
3楼-- · 2019-08-03 17:25

I presently get a table with lots of empty rows in bottom, only top 5-6 rows being used, with rest blank. I want to hide them or remove them somehow

Work the other way around. Start with an empty DefaultTableModel. DefaultTableModel supports an addRow() method. So, as you get data to add to the model use:

model.addRow(...);

Don't let the GUI editor determine how you code your GUI. Adding cleanup code to remove rows is a bad design.

查看更多
登录 后发表回答