如何在Netbeans中设置JList的ListModel? [英] How to set the ListModel of a JList in Netbeans?

查看:240
本文介绍了如何在Netbeans中设置JList的ListModel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

我想在Netbeans中指定一个地方传递DefaultListModel作为要在该JList中传递的模型,以便以后我可以检索它以在listModel中进行更改.

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.

我该怎么做.

推荐答案

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

You have two ways of doing this:

1)在您的代码中,在调用initComponents()之后的任何地方手动调用list.setModel(). 2)通过NetBeans完成-右键单击列表,转到自定义代码".第一个代码部分是列表的构造函数调用.将下拉列表从默认代码"更改为自定义创建",然后将ListModel插入构造函数调用中即可.您可以将其设置为新

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())

或在代码中对initComponents()的调用之前实例化您的listmodel,然后执行

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

javax.swing.JList(defaultModel);

这篇关于如何在Netbeans中设置JList的ListModel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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