Problem with JList, DefaultListModel and JScrollPane

Discussion in 'Java' started by Tobi Krausl, Nov 12, 2003.

  1. Tobi Krausl

    Tobi Krausl Guest

    Hi!

    I've the following problem with JList, DefaultListModel and
    JScrollPane:
    How can I get a JList (JScrollPane) which automatically scrolls down
    and shows the last entry added to the list?
    In my program there are several classes manipulating a
    DefaultListModel connected to a certain JList. To handle that, the
    constructor of each class gets a reference to that DefaultListModel.
    Ok, up to now it all works pretty fine. But if the JList gets bigger
    and Scrollbars are added, the user has to scroll down "manually" to
    see the bottom of the list. How can I handle the JList/JScrollPane to
    select and show always(!) the bottom of the list everytime myListModel
    changes??

    I tried the following:

    ..
    ..
    myList.addListSelectionListener(
    new ListSelectionListener() {

    public void valueChanged(ListSelectionEvent e) {
    int i=0;

    i=myListModel.getSize();

    myList.setSelectedIndex(i-1);
    myList.ensureIndexIsVisible(i-1);

    }
    }
    );
    ..
    ..

    This works, but only when the users clicks on the list.
    Could you please help me?

    Tnx so much,
    Tobi
     
    Tobi Krausl, Nov 12, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Konstantin Semlizki

    JScrollPane problem

    Konstantin Semlizki, Jul 8, 2004, in forum: Java
    Replies:
    1
    Views:
    1,110
    Roedy Green
    Jul 8, 2004
  2. Dipak

    JScrollPane Problem

    Dipak, Jul 27, 2004, in forum: Java
    Replies:
    3
    Views:
    855
    Andrew Thompson
    Jul 27, 2004
  3. Replies:
    2
    Views:
    976
    Roedy Green
    Sep 17, 2005
  4. Replies:
    3
    Views:
    1,645
    timjowers
    Jul 19, 2007
  5. yashiro

    Jscrollpane and jtable

    yashiro, May 17, 2008, in forum: Java
    Replies:
    2
    Views:
    1,977
    Jeff Higgins
    May 17, 2008
Loading...

Share This Page