将LinkedHasHSet的内容输出到JTable中 [英] Output the content of a LinkedHasHSet into a JTable
问题描述
我有一个LinkedHashSet
个Book
个对象. Book
对象具有以下字段:
private int id;
private String author = "";
private String title = "";
private boolean isRead;
private String dateStamp = "";
private static int counter = 0;
我希望他们进入我的JTable
,其中包含以下列:
String [] columnNames = {"ID","Title", "Author", "Status", "Date Read"};
我该怎么做?是否可以通过表格中的复选框来编辑isRead
字段?
AbstractTableModel
的具体示例,您可以利用LinkedHashSet
继承的toArray()
方法来简化getValueAt()
的实现,例如在相关的 EnvTableTest
中显示.默认的JTable
渲染器和编辑器使用JCheckBox
类型为Boolean.class
的TableModel
元素,如此示例所示.I have a LinkedHashSet
of Book
objects. The Book
objects have the following fields:
private int id;
private String author = "";
private String title = "";
private boolean isRead;
private String dateStamp = "";
private static int counter = 0;
I want them to go into my JTable
which has the following columns:
String [] columnNames = {"ID","Title", "Author", "Status", "Date Read"};
How can I do this? And is it possible to have the isRead
field being editable through a checkbox in the table?
As a concrete example of using AbstractTableModel
, you can leverage the toArray()
method inherited by LinkedHashSet
to simplify the implementation of getValueAt()
, as shown in this related EnvTableTest
. The default JTable
renderer and editor use JCheckBox
for TableModel
elements of type Boolean.class
, as shown in this example.
这篇关于将LinkedHasHSet的内容输出到JTable中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!