Java 库中是否有一个函数可以将 JTable 大小限制为您设置的行数?我似乎找不到任何可以帮助我的东西。
我的程序允许您在 JTable 中添加和删除项目。 JTable counts the number of rows in use and returns the number 有没有办法将行数限制为 100。
最佳答案
您可以在表数据模型上使用 setRowCount(int rowCount)
。
这将设置模型中的行数。如果新大小大于当前大小,则将新行添加到模型的末尾如果新大小小于当前大小,则丢弃索引 rowCount 和更大的所有行。
例如:
DefaultTableModel dtm = (DefaultTableModel) tabel1.getModel();
dtm.setRowCount(100); // though I would use some variable here
tabel1.setModel(dtm);
请找说明here.
关于java - 将 JTable 限制为 100 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22938649/