私のテーブルには 4 つの列があり、列 1 のみをクリックできるようにしたいです。また、このコードではマウスの左ボタンも使用できます。右ボタンのみが必要です。
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
int iCol = jTable1.getSelectedColumn();
if(iCol == 1 && evt.getModifiers() == InputEvent.BUTTON3_MASK)
{
if(evt.getClickCount() == 2)
{
int iRow = jTable1.getSelectedRow();
File iFile = new File(jTable1.getValueAt(iRow, iCol).toString());
String iPath = iFile.getAbsolutePath();
File iDir = new File(iPath.substring(0, iPath.lastIndexOf(File.separator)));
if(Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().open(iDir);
} catch (IOException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
}
この質問が2であることが判明した場合は申し訳ありません。