Observation::
Whenever the user reaches the last cell in the table and press Tab key, the focus is shifted to the first cell i.e the top the table.
Brought the table view back to the last cell, by using the function table.scrollRectToVisible(rect), but due this there is movement and looks like there is a false change in the table values.
The Scenario :: If I have make the make Scroll pane Static at p开发者_JAVA百科articular position, so that I can control the movement. How can make this possible..
Thank You in Advance...
The basic approach is to wrap the table's default navigation action into a custom Action which checks for the current cell: if it's the last, do nothing otherwise execute the wrapped action
code example:
Object key = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
.get(KeyStroke.getKeyStroke("ENTER"));
final Action action = table.getActionMap().get(key);
Action custom = new AbstractAction("wrap") {
@Override
public void actionPerformed(ActionEvent e) {
// implement your prevention logic
// here: don't perform if the current cell focus is the very cell of the table
int row = table.getSelectionModel().getLeadSelectionIndex();
if (row == table.getRowCount() - 1) {
int column = table.getColumnModel().getSelectionModel().getLeadSelectionIndex();
if (column == table.getColumnCount() -1) {
// if so, do nothing and return
return;
}
}
// if not, call the original action
action.actionPerformed(e);
}
};
table.getActionMap().put(key, custom);
精彩评论