This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable + JScrollPane manipulation  RSS feed

 
Chezhiyan Sivagurunathan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need help is changing the view area of my JTable. My JTable is inside a JScrollPane. I want to show the end of my JTable instead of the beginning.
 
Greg Brouelette
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did something like this many years ago. If I remember right I think I got the vertical scroll bar from the JScrollPane and then used the setValue() method of the JScrollBar to set it's position.
I also remember that it didn't work on a scroll pane wrapped around a JTextArea. I had to set the curser in the JTextArea to the end of the document because the JScrollPane would automatically scroll to wherever the curser was. If you see similar behavior with your JTable then maybe try seting the selected row to the end of your JTable.
Hope it helps.
 
Manoj Tyagi
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Greg
I am also facing the same problem. However, I tried the setSelectedRow() method. In this case cursor moves to that row, but Jscrollpane does not scroll to that place.
May be TextArea & JTable have different behavior with JScrollpane.
Manoj
 
Chezhiyan Sivagurunathan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried the following, it works
int lastIndex = tableModel.getRowCount() - 1;
Rectangle rect = histLsaTable.getCellRect(lastIndex, 0, true);
histLsaTopScrollPane.getViewport().scrollRectToVisible(rect);
Thanks everyone.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!