adding elements to a JList
ok...im feeling kinda dumb at the moment. in another program i used just a regular List where you could just say something like:
List.add(someString);
but now, i decided to use JList in combination with the BreezySwing gui package (mainly for school). so JList does not have the same methods as does List so i was wondering how i would go about adding elements to my list and have them displayed.
[416 byte] By [
anubis] at [2007-11-11 7:54:19]

# 2 Re: adding elements to a JList
yea, i've looked at that but i still cant seem to make it work lol
private JList nameList;
private DefaultListModel listModel;
// some code
nameList = addList(1,5,1,5); //just putting a blank list in the GUI (shows up at least)
// more code
listModel = new DefaultListModel();
String name = "";
if(buttonObj == addNameButton) // odd way of checking if the button was clicked but works =P
{
name = nameField.getText();
listModel.addElement(name);
nameList = new JList(listModel); //doesnt add anything to the list
}
so for some reason that doesnt work...havent been able to figure it out yet.
anubis at 2007-11-11 22:37:59 >

# 3 Re: adding elements to a JList
because you've created a new list model that isn't associated at all with the list you're using.
nameList = new JList(listModel);
listModel.addElement(name);
or
nameList.getModel().addElement(name);