How to install ListModel JList in Netbeans?

I developed the Swing GUI using the NetBeans IDE, and this GUI contains a JList.

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

I want to tell somewhere in Netbeans to pass the DefaultListModel as the model to be passed in this JList so that I can then get it to make changes to the listModel.

How can i do this.

+7
java user-interface swing netbeans jlist
source share
2 answers

You have two ways to do this:

1) In your code, list.setModel () is called manually anywhere after calling initComponents (). 2) Do it through NetBeans. Right-click the list, go to "Configure Code." The first section of code is a call to the list constructor. Change the Default Code drop-down list to Custom Creation and just paste your list into the constructor call. You can do this by installing it on a new one.

javax.swing.JList(new DefaultListModel()) 

or by creating an instance of listmodel before calling initComponents () in the code, and then do

 javax.swing.JList(defaultModel); 
+11
source share

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

+5
source share

All Articles