编辑行时JTable,更改ENTER动作?

时间:2013-06-10 01:45:50

标签: java swing jtable action enter

我有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);

        }
    });

1 个答案:

答案 0 :(得分:-1)

enter image description here

int key = evt.getKeyCode();

 if (key == KeyEvent.VK_ENTER) {

     //code here

 }

右键单击Jtable和事件,KeyReleased。