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 !
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL