DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2005

    Adding items to a JList at run time.

    This will probably seem like a very "noob" question but I think this is the appropriate forum for this?

    Anyway, I am VERY new to java and come from a .Net background. I am making an new JPanel and added some controls to the panel (text fields, check boxes, etc.) No problems there. Now, I've added a couple of Jlist controls at design time and they function properly.

    Now I want to be able to add string objects to a JList control at run time and can't figure out how. Here is my code that works when creating the control at "design time".

      String[] amountOfYears = 
           {"Select Years: 1", "Select Years: 2", "Select Years: 3", "Select Years: 4",
            "Select Years: 5", "Select Years: 6", "Select Years: 7", "Select Years: 8",
             "Select Years: 9", "Select Years: 10", "Select Years: 11", "Select Years: 12",
             "Select Years: 13", "Select Years: 14", "Select Years: 15", "Select Years: 16",
             "Select Years: 17", "Select Years: 18", "Select Years: 19", "Select Years: 20"};
            yearsListBox = new JList(amountOfYears);
            //Add the yearsListBox to the new scroll pane
            JScrollPane cardTypeScrollPane = new JScrollPane(yearsListBox);
    I just have no idea on how to remove all of these items, and then add new items.
    Any helps is much appreciated.

  2. #2
    Join Date
    Nov 2005
    Any help on this at all. I am not asking anyone to code this for me, just point me were to look. The book I have is either A) junk or B) over my head and assumes I am to know begginer methods.

  3. #3
    Join Date
    Sep 2005
    istanbul / Turkey
    you should use a class which extends AbstractListModel and implement its methods.

    public int getSize()
    public Object getElementAt(int n)

    first one will return an int value, it will be the number of items in your List model.
    second one will send the n. item of the model.
    List will call them and update it's view.
    its a very flexible design.
    (you can put a List or array in your class with add ,remove methods.)
    Last edited by mr1yh1; 11-27-2005 at 09:47 PM.

Similar Threads

  1. query tuning
    By dhaya in forum Database
    Replies: 11
    Last Post: 08-25-2003, 05:24 PM
  2. Replies: 1
    Last Post: 08-06-2002, 02:29 AM
  3. Run time Error '430'
    By Arunkumar in forum VB Classic
    Replies: 1
    Last Post: 07-03-2002, 06:18 AM
  4. run time error "3633"???
    By DH in forum VB Classic
    Replies: 1
    Last Post: 11-07-2001, 01:43 PM
  5. Adding AutoNumber field at run time
    By Setya in forum VB Classic
    Replies: 4
    Last Post: 07-05-2001, 10:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center