JTableのセルをダブルクリック
Total: 32577, Today: 1, Yesterday: 1
Posted by aterai at
Last-modified:
Summary
JTableのセルをダブルクリックして内容を表示します。
Screenshot

Advertisement
Source Code Examples
table.setAutoCreateRowSorter(true);
table.addMouseListener(new MouseAdapter() {
@Override public void mouseClicked(MouseEvent e) {
if (e.getClickCount() >= 2) {
Point pt = e.getPoint();
int idx = table.rowAtPoint(pt);
if (idx >= 0) {
int row = table.convertRowIndexToModel(idx);
String str = String.format(
"%s (%s)", model.getValueAt(row, 1), model.getValueAt(row, 2));
JOptionPane.showMessageDialog(
table, str, "title", JOptionPane.INFORMATION_MESSAGE);
}
}
}
});
View in GitHub: Java, KotlinDescription
JTableにMouseListenerを設定してMouseEvent#getClickCount()メソッドでマウスクリック数を取得し、これが2以上になる場合はセルがダブルクリックされたと判断JTableのセルはダブルクリックで編集開始がデフォルトなのですべてのセルを編集不可に設定