JList in Swing
Hopefully someone who uses Netbeans can help me, as that is what I'm using to generate my UI. If not, however, I'm sure basic Swing knowledge can also do the trick :D
I've created a JList object in my frame, and I have an array of objects "current" of a custom class "Game". In the Game class, there is a method called "getName()". Now I have a method that changes the array current based on user input. What I want to do is, when current changes, empty the list and add all the Strings from getName to it. So far I've had no luck adding anything at all to the list during runtime.
Help much appreciated, thanks.
[635 byte] By [
thefila] at [2007-11-27 11:51:45]

I don't have a clue what to give in terms of code... I guess this:
Sherlock sherlock = new Sherlock();
database = sherlock.sniff();
String[] data = new String[database.length-1];
for(int x = 0;x<data.length-1;x++){
data[x] = database[x].getName();
}
lstGames = new JList(data);
//lstGames.setSelectionModel(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
lstGames.setLayoutOrientation(JList.VERTICAL);
lstGames.setVisibleRowCount(-1);
jScrollPane1 = new JScrollPane(lstGames);
This is what I'm trying to use to change the list.>
> This is what I'm trying to use to change the list
change the model
DefaultListModel dlm = new DefaultListModel();
dlm.addElement(...); x # of items
list.setModel(dlm);