从jTable删除未使用的行 [英] Removing unused Rows from jTable

查看:93
本文介绍了从jTable删除未使用的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从JTable中删除未使用的行?

How do I remove unused rows from a JTable?

我首先在JPanel中创建一个固定大小的表,然后根据需要填充元素.

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.

推荐答案

我现在得到一个表格,其底部有很多空行,仅使用了顶部5-6行,其余为空白.我想隐藏它们或以某种方式删除它们

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

以其他方式解决.从一个空的DefaultTableModel开始. DefaultTableModel支持addRow()方法.因此,当您获得要添加到模型中的数据时,请使用:

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(...);

model.addRow(...);

不要让GUI编辑器确定如何编写GUI.添加清除代码以删除行是一个错误的设计.

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

这篇关于从jTable删除未使用的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆