Removing unused Rows from jTable

落花浮王杯 提交于 2019-12-11 05:37:21

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/15478688/removing-unused-rows-from-jtable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!