Swing/DoubleClick のバックアップ(No.21)
- バックアップ一覧
 - 差分 を表示
 - 現在との差分 を表示
 - 現在との差分 - Visual を表示
 - ソース を表示
 - Swing/DoubleClick へ行く。
  
- 1 (2004-06-28 (月) 05:48:37)
 - 2 (2004-06-28 (月) 05:48:50)
 - 3 (2004-07-09 (金) 07:36:59)
 - 4 (2004-10-08 (金) 06:19:01)
 - 5 (2004-11-04 (木) 10:04:24)
 - 6 (2005-02-03 (木) 02:03:57)
 - 7 (2005-04-28 (木) 04:33:05)
 - 8 (2005-10-10 (月) 23:24:58)
 - 9 (2006-02-16 (木) 22:24:46)
 - 10 (2006-02-27 (月) 15:49:34)
 - 11 (2006-04-12 (水) 19:42:13)
 - 12 (2006-07-14 (金) 16:26:58)
 - 13 (2007-05-04 (金) 03:27:24)
 - 14 (2009-01-20 (火) 15:03:30)
 - 15 (2011-02-02 (水) 18:34:20)
 - 16 (2011-06-30 (木) 16:04:50)
 - 17 (2012-07-06 (金) 17:35:33)
 - 18 (2013-04-10 (水) 02:44:49)
 - 19 (2015-01-30 (金) 19:31:04)
 - 20 (2016-08-04 (木) 19:17:34)
 - 21 (2017-09-30 (土) 23:37:20)
 - 22 (2019-04-03 (水) 19:35:13)
 - 23 (2021-01-12 (火) 10:32:00)
 - 24 (2023-07-11 (火) 09:55:37)
 - 25 (2025-01-03 (金) 08:57:02)
 - 26 (2025-01-03 (金) 09:01:23)
 - 27 (2025-01-03 (金) 09:02:38)
 - 28 (2025-01-03 (金) 09:03:21)
 - 29 (2025-01-03 (金) 09:04:02)
 - 30 (2025-01-08 (水) 10:49:28)
 - 31 (2025-06-19 (木) 12:41:37)
 - 32 (2025-06-19 (木) 12:43:47)
 
 
- category: swing
folder: DoubleClick
title: JTableのセルをダブルクリック
tags: [JTable, MouseListener]
author: aterai
pubdate: 2004-06-28T05:48:37+09:00
description: JTableのセルをダブルクリックして内容を表示します。
image: 

 
概要
JTableのセルをダブルクリックして内容を表示します。
Screenshot

Advertisement
サンプルコード
table.setAutoCreateRowSorter(true);
table.addMouseListener(new MouseAdapter() {
  @Override public void mouseClicked(MouseEvent me) {
    if (me.getClickCount() == 2) {
      Point pt = me.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, Kotlin解説
上記のサンプルでは、JTableにMouseListenerを設定し、マウスでのセルのマウスでダブルクリックイベントを取得しています。各セルはクリックで編集状態になってしまわないように、すべて編集不可にしています。