Question about Adjusting JScrollPane
hello, I'm new to java GUI programming, and I have a question:
I've created a list box that's connected to a JScrollPane in order to show the scroll bar.
it works fine. however, when lines inserted to the listbox exceed it's buttom border, the scrollbar indeed strech, but stay at the top of the listBox.
how can I make it, that it will alway dynamicly be as low as it can ?
thanx in advance.
Try setting the selected index of the JList to the most recently added one (the one at the bottom I'm guessing).
I thought of that already,
it marks the buttom line, but doesn't scroll down to it, you have to do it manually to see the selected last line...
Ah, sorry about that. Take a look at the JList API. Inheriting from JComponent is a method "scrollRectToVisible". That should do the trick. Just call getCellBounds on the last cell and then perform a scrollRectToVisible on it.
Hope this helps.
Thanx a lot man! it works !
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center