8

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.

4

2 回答 2

11

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);
于 2010-01-22T14:32:52.070 回答
6

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

于 2010-07-30T04:29:17.050 回答