JTable:如何添加数据而不显示?
我有一个图像专栏。我想附加一些只能阅读但不能显示的附加文本信息。
我怎样才能做到这一点?我正在寻找一些“幽灵”专栏。
寻找某种方法来存储临时存储在客户端java应用程序上的持久数据,然后将其上传到服务器。
I have a column for images. I would like to attach some additional text information that will only be read but not for display.
How can I achieve this ? I am looking for some "ghost" column.
Looking for some way to store persistent data that stores temporarily on client java application, and later uploads it to the server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
现在,当您想要引用隐藏列中的数据时,您需要从 TableModel 而不是 JTable 获取数据:
Now when you want to reference the data in the hidden column you need to get the data from the TableModel, not the JTable:
了解您的
TableModel
的外观会很有帮助,因为我们可以为您提供对当前设计进行最小更改的想法。但是,一种解决方案是设计一个自定义数据对象来表示表中的一行,并让您的TableModel
使用它为每列提供正确的数据,包括您当前显示的图像。编辑:
我建议您通过扩展
AbstractTableModel
创建自己的TableModel
。为此,您只需要实现三个方法:然后您可以提供一个像
List
这样的后备集合来保存行数据。您的getRowCount()
可以返回列表的大小,您的getColumnCount()
可以为图片列返回1
。然后,getValueAt()
将从上面提到的自定义数据对象中返回图片。It would be helpful to see what your
TableModel
looks like, as we could give you ideas that would offer minimal changes to your current design. However, one solution would be to design a custom data object that would represent a row in your table, and have yourTableModel
use it to supply the correct data for each column, including the image that you currently display.edit:
I would suggest that you create your own
TableModel
by extendingAbstractTableModel
. For that you just need to implement three methods:You then could provide a backing collection like a
List
to hold your row data. YourgetRowCount()
could return the size of the list, yourgetColumnCount()
could return1
for your picture column.getValueAt()
would then return the picture from the custom data object that I mentioned above.您需要扩展 AbstractTableModel 或 DefaultTableModel 类并重写 getValueAt(row,column) 和 setValueAt 方法。
You need to extend AbstractTableModel or DefaultTableModel class and override getValueAt(row,column) and setValueAt methods.
您使用的是自定义 TableModel 吗?您可以像这样覆盖
getColumnCount()
:这样您的模型将隐藏最后一列,但您仍然可以使用
getValueAt()
读取它Are you using a custom TableModel? You can override
getColumnCount()
like this:This way your model will have the last column hidden, but you'll still be able to read it with
getValueAt()