如何列出绑定到 JList?

发布于 2024-11-06 18:24:15 字数 181 浏览 1 评论 0原文

我有Jlist。我需要来自 List

Mytype的绑定信息

public class MyType {

    String _title = "";
    String _description = "";
}

I have Jlist. I need binding info from List<MyType>

Mytype

public class MyType {

    String _title = "";
    String _description = "";
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

北风几吹夏 2024-11-13 18:24:15

您需要将数据绑定到 JList 数据模型 (ListModel)。

You need to bind your data to JList data model (ListModel).

过潦 2024-11-13 18:24:15

如果您的意思是绑定为“如果我更新列表,JList 也会更新,反之亦然”,您正在寻找类似的内容: BeansbindingGlazed Lists。如果您只想将 List 的每个对象显示为 JList 中的项目,请覆盖 MyType toString 方法并编写一些不好的代码,如下所示:

  List<MyType> list = ...
  JList jList = new JList(list.toArray());

或者实现您自己的 列表模型。我绝对会建议您使用库而不是重新启动轮子方法。

If you mean binding as "if I update my List the JList will also be updated and vice-versa" you are looking for something like: Beansbinding or Glazed Lists. If you just want to display every object of List<MyType> as an item in the JList, override MyType toString method and write some bad code such as this:

  List<MyType> list = ...
  JList jList = new JList(list.toArray());

Or implement your own ListModel. I would definitely advice you to go with the libraries instead of the reiventing the wheel approach.

菊凝晚露 2024-11-13 18:24:15
//First Create Get and Set Methods
public class MyType {
    String title = "";
    String description = "";

    public String getDescription() {
        return _description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
}

//Then set to List    
List<MyType> tmpList = new ArrayList<MyType>();

MyType tmpMyType = new MyType();
tmpMyType.setTitle("Maths");
tmpMyType.setDescription("Algibra");

tmpList.add(tmpMyType);
//First Create Get and Set Methods
public class MyType {
    String title = "";
    String description = "";

    public String getDescription() {
        return _description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
}

//Then set to List    
List<MyType> tmpList = new ArrayList<MyType>();

MyType tmpMyType = new MyType();
tmpMyType.setTitle("Maths");
tmpMyType.setDescription("Algibra");

tmpList.add(tmpMyType);
逐鹿 2024-11-13 18:24:15

我不太确定我是否理解你的问题,但你在寻找:

JList <MyType> myList = new JList <MyType> ();

I am not quite sure if I understood your question, but are you looking for:

JList <MyType> myList = new JList <MyType> ();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文