2016-04-05 45 views

回答

1

新值可以从DefaultCellEditor得到。

button.addActionListener(new ActionListener() { 
     public void actionPerformed(ActionEvent e) { 

      if (table.getCellEditor() != null) { 
       DefaultCellEditor cellEditor = (DefaultCellEditor) table.getCellEditor(); 
       String value = ((JTextField) cellEditor.getComponent()).getText(); 
      } 

     } 
    }); 
+0

plz告诉我在哪里添加此代码 –

+0

您的按钮的动作侦听器。 – rdonuk

+0

检查我更新的代码。 – rdonuk

0

也许this解决方案将够你:

table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); 

它不仅节省了当“保存”按钮被点击,而且在重点的变化等情况下,所有表数据。

相关问题