How to scroll to a cell in a JTable
- From: Josef Garvi <josef_NOSPAM@xxxxxxxxxxxxxxxxxxx>
- Date: Wed, 27 Apr 2005 14:37:23 +0200
I have a JTable embedded in a JScrollPane.
Through code, I want to select a specific cell in the table and make sure it scrolls into view.
Here is my code (note: my JTable only has one row, but a large number of columns):
int index = 5; // column that I want to show
tblDiscContent.getColumnModel().getSelectionModel().
setSelectionInterval(index, index);scrollDiscContent.getViewport().scrollRectToVisible(
tblDiscContent.getCellRect(
0,tblDiscContent.convertColumnIndexToView(index), false));The last statement should scroll the cell into view, but it doesn't. It scrolls too far to the right, leaving my cell hidden to the left. The amount of error does is not constant and depends on which cell I try to select.
-- Josef Garvi
"Reversing desertification through drought tolerant trees" http://www.eden-foundation.org/
new income - better environment - more food - less poverty .
- Follow-Ups:
- Re: How to scroll to a cell in a JTable
- From: Josef Garvi
- Re: How to scroll to a cell in a JTable
- Prev by Date: Re: using JOptionPane's error icon
- Next by Date: Re: Hide Maximize Button of JFrame And Problems!
- Previous by thread: using JOptionPane's error icon
- Next by thread: Re: How to scroll to a cell in a JTable
- Index(es):