2015-06-21 69 views
0

我直接將數據插入到JTable中,假設JTable中有5行,我插入了所有值,最後我在第五行的單元格中插入值,並且單元格處於在這種情況下,我無法讀取該單元格的數據。無法從JTable可編輯單元格讀取數據

+0

您應該添加一些代碼,以便我們可以知道您正在嘗試做什麼...... –

+0

您是從程序角度講話還是使用視角?請記住 - 您必須在GUI中以用戶身份離開單元,以便能夠從程序端讀取它。只需點擊最後一個單元格外的某個地方,即可完成編輯,程序可以讀取數據。 – Alex

回答

0

之前設置或JTable必須取消從細胞獲得價值/停止editing.You可以通過

做到這一點假設jTable1是的JTable

/** 
* Tells the editor to stop editing and accept any partially edited 
* value as the value of the editor. The editor returns false if 
* editing was not stopped; this is useful for editors that validate 
* and can not accept invalid entries. 
* 
* @return true if editing was stopped; false otherwise 
*/ 

jTable1.getCellEditor().stopCellEditing(); 

或varaible名

/** 
* Tells the editor to cancel editing and not accept any partially 
* edited value. 
*/ 
jTable1.getCellEditor().cancelCellEditing(); 
相關問題