Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scrollRectToVisible --> need effect on vertical line

I have JTable with two scrollbars (horizontal and vertical). When I use scrollRectToVisible, it return me Rectangle and this action cause that vertical and horizontal scrollbars automatically move to specified rows/columns. How can I move automatically vertical scrollbar to desired place and horizontal scrollbar should stay inactive? This method should show me selected row but my JTable is very wide and I would like to avoid automatically movement (horizontal) at the beginning (left side) of track -> simple say, I expect that horizontal position is unchanged.

public void goToSelected() {

    int selectedRow = this.getSelectedRow();
    if (selectedRow >= 0)

    this.scrollRectToVisible(this.getCellRect(selectedRow, 0, true));
}
like image 599
mattipr Avatar asked Mar 31 '26 16:03

mattipr


1 Answers

The horizontal position might change because you are specifying a column index (0) and the specified column might be invisible. You can simply combine the values of the currently visible area and the cell’s vertical range to get the desired effect:

Rectangle target = getCellRect(selectedRow, 0, true), vis = getVisibleRect();
target.x = vis.x;
target.width = vis.width;
scrollRectToVisible(target);
like image 155
Holger Avatar answered Apr 03 '26 15:04

Holger