gpt4 book ai didi

java - 将 JTable 限制为 100 行

转载 作者:行者123 更新时间:2023-11-29 05:25:11 26 4
gpt4 key购买 nike

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com