私はこのコードを持っています:
listTable.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 1) {
JTable target = (JTable)e.getSource();
int row = target.getSelectedRow();
int column = target.getSelectedColumn();
String title = listTable.getValueAt(row, column).toString();
String duration = listTable.getValueAt(row, column+1).toString();
String genre = listTable.getValueAt(row, column+2).toString();
String actor = listTable.getValueAt(row, column+3).toString();
String director = listTable.getValueAt(row, column+4).toString();
//String rentable = listTable.getValueAt(row, column+5).toString();
//String synopsis = listTable.getValueAt(row, column+6).toString();
txtTitle.setText(title);
txtDuration.setText(duration);
txtGenre.setText(genre);
}
});
これにより、次のことが可能になります。
- 行が選択されると、列の値が JTextBoxes に渡されます。
ただし、デフォルトで最初の列をクリックしないと、選択が文字化けします。たとえば、最初に「タイトル」列をクリックせずに「期間」列をクリックすると、期間がtxtTitleに入れられ、他のものも混同されます。
行が選択されたときに最初の列をデフォルトで選択するコードを追加するにはどうすればよいですか?
これは何が起こるかのスクリーンショットです:
ありがとう、ブライアン