• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JTable and ScrollPane movement

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I made a JTable and populated it using JDBC. I am able to scroll down through the rows using the scrollbar but I also created buttons to move the selected row up by one, down by one, to the first row, and to the last row. The problem is when I click on the last row button is does make the last row in the JTable the selected row but it doesn't move the scroll bar down to make the last row visible (I still have to move the scroll bar down). The same happens if I'm at the end of the table and I click on the first row button. Also, if I keep clicking the next row button when the selected row disappears from the viewable area it does not automatically move the scroll bar. Do I have to do this manually? Thanks.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Richard,
No, you don't have to do it manually. You just need to do two things: obtain a Rectangle that identifies the coordinates and size of a cell that you want to make visible, and then use JViewport's scrollRectToVisible() method to make that cell visible. (The JViewport can be accessed by calling the JScrollPane's getViewport() method). For example, let's suppose that you've

This assumes that you aren't concerned with horizontal scrolling, but even if you are, you can use the same technique with very little additional code.
------------------
Brett Spell
Author, Professional Java Programming
 
That feels good. Thanks. Here's a tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic