gpt4 book ai didi

java - ArrayList 与 jList 的自定义类

转载 作者:行者123 更新时间:2023-12-01 18:43:23 25 4
gpt4 key购买 nike

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

在这个 JFRAME 中,我有 jList 如何在 jList 中设置 ArrayList 中的所有行并采用如下格式:

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

我尝试使其适用于数组列表中的每个元素,但不起作用。

最佳答案

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

关于java - ArrayList 与 jList 的自定义类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18976574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com