Results 1 to 3 of 3

Thread: jList

  1. #1

    Thread Starter
    Hyperactive Member xxarmoxx's Avatar
    Join Date
    Mar 2007
    Posts
    378

    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

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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

  3. #3

    Thread Starter
    Hyperactive Member xxarmoxx's Avatar
    Join Date
    Mar 2007
    Posts
    378

    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:

    Code:
    jList1 = jList;
    (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
  •  



Click Here to Expand Forum to Full Width