ArrayList with custom class to jList



我有ArrayList of Children,并且有一些属性(全名(String),age(int),parent_id(int),id(int))。我正在使用 netbeans 设计视图来创建 JFrame(对我来说更容易定位元素)。

在这个 JFRAME 中,我有 jList,我可以如何在 jList 上设置来自 ArrayList 的所有行并设置这样的格式:

String.format("%s t %d",ch.getFullName(),ch.getAge()) .

我试图从数组列表中为每个元素制作它,但不起作用。

将所有

子类添加到JList模型中并定义自定义ListCellRenderer。在渲染器中获取值并使用 Children 元素设置文本。

JTable 是呈现多列数据的更好选择。有关详细信息,请参阅 Swing 教程中有关如何使用表的部分。

DefaultTableModel 不支持具有自定义对象的 ArrayList,因此您可以尝试使用行表模型。

最新更新