Results 1 to 4 of 4

Thread: Setting up a JScrollPane ?

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Setting up a JScrollPane ?

    Im trying to create a JScrollPane that contains a JList which is populated with entries which are just Strings. For some reason i get nothing visually at all. When i set the JScrollPane to use scrollbars all of the time what is the default size of the JScrollPane?

    Code:
    public GUI(){
    JScrollPane jsp = new JScrollPane();
      jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); 
      jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    }

  2. #2

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Ok i can now see my JList which is in a JScroll pane. Now how would i go about adding objects to the JList? When i pass in a String[] array to the constructor the JList ends up being empty.

  3. #3
    Addicted Member
    Join Date
    May 2001
    Location
    UK
    Posts
    222

    Jlist

    I had an anoying time with JList when i first started playing with them, as i found no easy way to add and remove objects and have the list update properly, so i wrote a List model that implemnts Default List Model and the List interfaces (see attached)


    Just Create list:
    Code:
    GenericListModel model = new GenericListModel();
    JList list = new JList(model);
    
    this.add(new JScrollPane(list));
    now you can use any methods on the model and they will be reflected in the JList...


    Is that what you needed or meant?

    Andy
    Attached Files Attached Files

  4. #4

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    So essentially what needs to be done is that i have to create a class that implements the javax.swing.ListModel interface, provide implementation for the four methods that are contained within in the interface then pass in an instance of this class to a JList constructor.

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