Editing auto generated code by netbeans

Viewed 1391

With Netbeans, I have created a GUI form and added a JList component. In order to add items, I have create a ListModel according to many websites.

DefaultListModel<String> model = new DefaultListModel<>();
JList<String> list = new JList<>( model );

Problem is that the second line is automatically generated by Netbeans and it is not editable! So, I see

private javax.swing.JList<String> list;
...
list = new javax.swing.JList<>();

So how can I change that line to JList<>( model )? I have to say that in the generated code, I see

 list.setModel(new javax.swing.AbstractListModel<String>() {
        String[] strings = { "String" };
        public int getSize() { return strings.length; }
        public String getElementAt(int i) { return strings[i]; }
    });

I don't know how that can be used. I see some questions similar to mine, but it is not clear for me what is exactly the problem and why I can not add/remove items in a normal way as expected!

1 Answers
Related