我想從Jtable中獲取值,然後使用getvalueat嘗試它,但是每當我嘗試從JTable獲取值時,它只會從第一列中獲取值選定的行,我需要從我選擇的Jtable中獲取所有值。能否請你幫我這個一個Java獲取JTable值(每行)
here is my code:
class GetTableValue implements ActionListener{
public void actionPerformed(ActionEvent e){
AbstractButton button = (AbstractButton)e.getSource();
if(e.getActionCommand().equals(button.getActionCommand)){
int row = table.getSelectedRow();
int col = table.getSelectedColumn();
Object data = (Object)table.getValueAt(row, col);
JOptionPane.showMessageDialog(null, data);
}
}
}
這不是我的操作事件,其中在JOptionPane中所示遺憾的是它只能顯示一個值(這是你已經選擇了一個)選定表的值計算全行。
此代碼是我的JButton呼叫的動作事件(我已經排除在JTable中我的代碼,因爲它獲取從我的數據庫JTable中值)
ActionListener tableAction = new GetTableValue();
buttonEdit = new JButton("EDIT");
buttonEdit.addActionListener(tableAction);
代碼是簡單明瞭的,我也搜索先生G(谷歌)關於獲取行的一個很好的教程,遺憾的是沒有一個很好的教程獲取Jtable值(每行)。
我建議你從SwingX框架中使用JXTable。 – brainless
請將Swing標籤添加到使用Swing組件的帖子中!我希望最近幾次我爲你做了這件事,*可能會給你提示。 –