DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2005
    Posts
    9

    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.

  2. #2
    Join Date
    Aug 2003
    Posts
    313
    Try setting the selected index of the JList to the most recently added one (the one at the bottom I'm guessing).
    ~evlich

  3. #3
    Join Date
    May 2005
    Posts
    9
    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...

  4. #4
    Join Date
    Aug 2003
    Posts
    313
    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.
    ~evlich

  5. #5
    Join Date
    May 2005
    Posts
    9
    Thanx a lot man! it works !

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links