Link to home
Start Free TrialLog in
Avatar of YamunaiThuraivan
YamunaiThuraivan

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Ovi
Ovi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ovi
Ovi

The two method calls must be used in the 'addRow' portion of your code.
Avatar of Mick Barry
You need to define a TableModelListener and a TreeSelectionListener that scrolls to the added/selected row.
Aren't the listeners unnecesary in this case too ?
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.