如何在Netbeans中设置JList的ListModel?

发布于 2024-08-18 15:00:50 字数 243 浏览 3 评论 0原文

我在 Netbeans IDE 的帮助下设计了一个 Swing GUI,该 GUI 包含一个 JList。

默认情况下,它使用 AbstractListModel 将其作为 JList 构造函数中的参数传递以创建该 JList。

我想在 Netbeans 中的某个位置指定传递 DefaultListModel 作为要在该 JList 中传递的模型,以便稍后我可以检索它以在 listModel 中进行更改。

我该怎么办呢。

I have designed a Swing GUI with the help of Netbeans IDE and this GUI contains a JList.

Bydefault, it uses AbstractListModel to pass it as an argument in the JList contructor to create that JList.

I want to specify somewhere in the Netbeans to pass DefaultListModel as the model to be passed in that JList so that later I can retrieve it to make changes in the listModel.

How can I do that.

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

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

发布评论

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

评论(2

当梦初醒 2024-08-25 15:00:50

有两种方法可以做到这一点:

1) 在代码中,在调用 initComponents() 之后的任意位置手动调用 list.setModel() 。
2) 通过 NetBeans 执行此操作 - 右键单击​​列表,转到“自定义代码”。第一个代码部分是列表的构造函数调用。将下拉列表从“默认代码”更改为“自定义创建”,然后只需在构造函数调用中插入您的 ListModel 即可。您可以通过将其设置为 new

javax.swing.JList(new DefaultListModel())

或在代码中调用 initComponents() 之前实例化 listmodel 来完成此操作,然后执行

javax.swing.JList(defaultModel);

You have two ways of doing this:

1) In your code manually call list.setModel() anywhere after initComponents() is called.
2) Do it through NetBeans - Right click the list, go to "Customize Code". The first code section is the list's constructor call. Change the dropdown from "Default Code" to "Custom Creation" and simply insert your ListModel in the constructor call. You can do this by setting it to new

javax.swing.JList(new DefaultListModel())

or by instantiating your listmodel before the call to initComponents() in the code and then doing

javax.swing.JList(defaultModel);
香橙ぽ 2024-08-25 15:00:50

我通常在 Netbeans 中这样做
1. 选择JList
2. 在model属性中,选择自定义代码并插入listModel名称(在第3步中声明)
3. 在代码视图中声明 DefaultListModel listModel = new DefaultListModel();
4. 更改 listModel 声明以接受 List 或类似的

I usually do this way in Netbeans
1. Select the JList
2. In model property, select Custom code and insert the listModel name (declared in 3rd step)
3. declare DefaultListModel listModel = new DefaultListModel(); in code view
4. change listModel declaration to accept a List or similar

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