i want to add a String Array to a list box in Netbeans.
i tried several ways after searching in google. but couldnt get a single one working. can someone help me please
i want to add a String Array to a list box in Netbeans.
i tried several ways after searching in google. but couldnt get a single one working. can someone help me please
String[] arr = {"one", "two", "three"};
listbox.setListData(arr); //listbox is your JList object
See: http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JList.html
If you want to add the items through the GUI builder tool, do as follows:
Drag and Drop the JList Component onto your parent container
Select the List component you have just dragged by clicking on it and on the right hand side, chose Properties.
From the list of items at the top (like Background, Border, Font, etc) click on Model (by default it has the following items in it: Item 1, Item 2, etc.). Click on the button that has three ellipses (it is on the same row) and a window should open. It should have the following items:
Item 1
Item 2
Item 3, etc.
Delete those and put in the items you want to add and press ok.
That is how it is done through the Netbeans GUI builder. If you want to do it programmatically, do as genessis suggets.