|
-
Jun 6th, 2007, 01:49 PM
#1
Thread Starter
Hyperactive Member
jList
For the love of sweet jesus I have spent the last hour trying to figure out how to add strings to a jList from a button. How can I do this?
Lets say I want to add "A" "B" "C" "D" to jList1 which has already been drawn on the form. Thanks
-
Jun 6th, 2007, 03:20 PM
#2
Re: jList
Next time try taking a look at the JDoc before asking such a question
Code:
// Create a JList that displays strings from an array
String[] data = {"one", "two", "three", "four"};
JList myList = new JList(data);
// Create a JList that displays the superclasses of JList.class, by
// creating it with a Vector populated with this data
Vector superClasses = new Vector();
Class rootClass = javax.swing.JList.class;
for(Class cls = rootClass; cls != null; cls = cls.getSuperclass()) {
superClasses.addElement(cls);
}
JList myList = new JList(superClasses);
// The automatically created model is stored in JList's "model"
// property, which you can retrieve
ListModel model = myList.getModel();
for(int i = 0; i < model.getSize(); i++) {
System.out.println(model.getElementAt(i));
}
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jun 6th, 2007, 04:12 PM
#3
Thread Starter
Hyperactive Member
Re: jList
your code compiles but the only thing is I have already added the jList to the project before hand so dynamically creating a new jList doesnt do anything. I tried doing:
(The already created jList on the form is named 'jList1')
but nothing appears in the jListbox. What am I doing wrong?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|