Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Problem with JList, DefaultListModel and JScrollPane

Reply
Thread Tools

Problem with JList, DefaultListModel and JScrollPane

 
 
Tobi Krausl
Guest
Posts: n/a
 
      11-12-2003
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Jscrollpane and jtable yashiro Java 2 05-17-2008 11:52 AM
JTable and JScrollPane helmut.teichmann@opb.de Java 3 07-19-2007 12:35 PM
Swing DefaultListModel question. stroker_ace@hotmail.com Java 2 09-17-2005 07:35 AM
JScrollPane Problem Dipak Java 3 07-27-2004 03:32 PM
JScrollPane problem Konstantin Semlizki Java 1 07-08-2004 07:18 PM



Advertisments