我对JTable有问题。我需要编辑一些行,但是当我完成并按Enter时,我想要更改操作,例如保存在数据库中。这是我的代码:
// JTable PDV
tablePDV = new JTable(pdvTableModel) {
// Editable Enable || Disable
public boolean isCellEditable(int rowIndex, int colIndex) {
if (check == true) {
if (rowIndex == rowSelectedIndex
&& colIndex == colSelectedIndex) {
return super.isCellEditable(rowIndex, colIndex);
}
}
return false;
}
};
tablePDV.addMouseListener(new MouseAdapter() {
@Override
public void mouseExited(MouseEvent arg0) {
tablePDV.clearSelection();
tablePDVSecond.clearSelection();
}
@Override
public void mouseClicked(MouseEvent e) {
tableMousClick(tablePDV, e, 436, 455, 477, 498, 1);
}
});
最佳答案
int key = evt.getKeyCode();
if (key == KeyEvent.VK_ENTER) {
//code here
}
右键单击Jtable和event,KeyReleased。