我按Tab键时遇到问题,它总是水平移动一行。如果想要按下Tab键,它将在下一列中移动。任何人都可以使用java中的JTABLE通过代码告诉解决方案。在此先感谢:)
这是我的代码:
@覆盖 public void keyPressed(KeyEvent k){
int key = k.getKeyCode();
if (key == KeyEvent.VK_TAB) {
//transferFocus();
// transferFocusDownCycle();
// table.setFocusTraversalKeysEnabled(false);
int row = table.getSelectedRow();
int col = table.getSelectedColumn();
System.out.println("Row : "+row);
System.out.println("column : "+col);
int colCount = table.getColumnCount();
int rowCount = table.getRowCount();
//boolean selrow = table.isRowSelected(1);
col++;
if (col >= colCount) {
col = 0;
row++;
}
System.out.println("After col++ :"+col);
System.out.println("colcount : "+colCount);
if (row >= rowCount) {
row = 0;
}
System.out.println("After row++ : "+row);
System.out.println("rowcount : "+rowCount);
table.getSelectionModel().setSelectionInterval(row, row);
table.getColumnModel().getSelectionModel().setSelectionInterval(col, col);
}