T
Tobi Krausl
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
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