This week's book giveaway is in the Agile and Other Processes forum. We're giving away four copies of Software Teaming: A Mob Programming, Whole-Team Approach and have Woody Zuill and Kevin Meadows on-line! See this thread for details.
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.
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