-2
ユーザーが行をダブルクリックしたときに、選択した行のインデックスを取得したいとします。私はテーブルの行をダブルクリックにもかかわらずマウスクリックJTableのイベント
tab.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
int selectedRow = tab.getSelectedRow();
try {
String file = rows[selectedRow][2];
String path = "C:\\Users\\raj kumar\\Gallery\\" + file;
JLabel fileLable = new JLabel();
fileLable.setBounds(500, 600, 300, 300);
fileLable.setIcon(new ImageIcon(path));
pan.add(fileLable);
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
});
しかしtab.getSelectedRow()
戻り-1
:
は、ここに私のコードです。