• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 360
  • Last Modified:

question regarding JTable

Hi,
       I have  a JTable which is enclosed in a JScrollPane.There are lot of rows in the table so that the total is not visible.vertical scroll bar is present.I have to move the scroll bar down to see some of the rows at the last.At this scenario,if I add a row to the table, the scroll pane is not displaying the added row(last row).it is not scrolling down to display it.How to programatically scroll down in a table if some row is added or selected
thanks in advance,
YamunaiThuraivan
0
YamunaiThuraivan
Asked:
YamunaiThuraivan
  • 3
  • 2
1 Solution
 
OviCommented:
something like

Rectangle r = table.getCellRect(row, col); // returns the rectangle of a cell from your last row added

tableScrollPane.getViewport().scrollRectToVisible(r);
0
 
OviCommented:
The two method calls must be used in the 'addRow' portion of your code.
0
 
objectsCommented:
You need to define a TableModelListener and a TreeSelectionListener that scrolls to the added/selected row.
0
 
OviCommented:
Aren't the listeners unnecesary in this case too ?
0
 
objectsCommented:
It's a far more flexible way to do it. The addRow() may not (and does not need) access to the table or the scroll pane. Additionally it is possible to add rows to the table without calling addRow() thus subverting your auto scrolling.
By implementing it as a TreeModelistener, you not only ensure it's called whenever a row is added, but you also have full control over it.

Ignore the mention of the TreeSelectionListener I misread the question.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now