问题
First question on stackoverflow ;-)
Similar question to here, only I am trying to scroll a NAT-Table programmatically. I can neither show a selected Item, nor set a value to the Scrollbar itself (via getHorizontalBar or similar).
The internet wields no answers, as far as I could see, and solutions suggested for other swt controls do not seem to apply...
回答1:
That depends on what you are trying to achieve. Do you want to select a cell and move it into the viewport, or do you simply want to move cells into the viewport without selection?
For simply moving cells into the viewport you should try the corresponding commands to achieve this:
- ShowRowInViewportCommand
- ShowColumnInViewportCommand
ShowCellInViewportCommand
natTable.doCommand(new ShowRowInViewportCommand(gridLayer.getBodyLayer(), 50));
To achieve selection and moving a row into the viewport, you could use the corresponding selection commands:
- SelectRowsCommand
- SelectColumnCommand
SelectCellCommand
natTable.doCommand(new SelectRowsCommand(gridLayer.getBodyLayer(), 0, 50, false, false));
Note that you need to consider the position/index transformations, which means the above statement will select the 51 row in the grid because of the column header.
来源:https://stackoverflow.com/questions/17593049/scroll-nattable-programmatically