将LinkedHasHSet的内容输出到JTable中 [英] Output the content of a LinkedHasHSet into a JTable

查看:79
本文介绍了将LinkedHasHSet的内容输出到JTable中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个LinkedHashSetBook个对象. 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.classTableModel元素,如此示例所示.

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屋!

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