からデータを取得したいのですJTable
が、次のコード行では実行できません。
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {
d= (DefaultTableModel)jTable1.getModel();
int c = d.getColumnCount();
System.out.println("number of cilumn is"+c);
int selectIndex = d.getRowCount();
System.out.println("selected row is "+selectIndex);
jTextField1.setText(d.getValueAt(selectIndex, 1).toString());
jTextField2.setText(d.getValueAt(selectIndex, 2).toString());
jTextField3.setText(d.getValueAt(selectIndex, 3).toString());
jTextField4.setText(d.getValueAt(selectIndex, 4).toString());
jTextField5.setText(d.getValueAt(selectIndex, 5).toString());
jTextField6.setText(d.getValueAt(selectIndex, 6).toString());
jButton1.setEnabled(false);
}
int selectIndex = d.getRowCount();
上記は2つの理由で正しくありません:
Javaのインデックスはゼロベースです。テーブルに1行しかない場合、インデックスとして1を使用しようとすると、例外が発生します。
行数は、クリックした行のインデックスを提供しません。
クリックした行のデータが必要な場合、コードは次のようになります。
int selectIndex = jtable1.getSelectedRow();
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加