Swing/SingleClickCellEdit のバックアップ(No.18)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/SingleClickCellEdit へ行く。
- 1 (2007-11-19 (月) 13:45:37)
- 2 (2007-11-22 (木) 20:03:47)
- 3 (2007-12-18 (火) 12:14:32)
- 4 (2008-06-24 (火) 12:51:43)
- 5 (2013-01-29 (火) 14:44:32)
- 6 (2013-08-16 (金) 16:37:55)
- 7 (2013-08-23 (金) 15:14:25)
- 8 (2014-11-25 (火) 03:03:31)
- 9 (2015-02-18 (水) 15:10:33)
- 10 (2016-11-10 (木) 15:27:05)
- 11 (2017-11-18 (土) 13:59:04)
- 12 (2018-10-05 (金) 01:16:49)
- 13 (2020-10-01 (木) 18:16:12)
- 14 (2022-06-08 (水) 17:28:20)
- 15 (2025-01-03 (金) 08:57:02)
- 16 (2025-01-03 (金) 09:01:23)
- 17 (2025-01-03 (金) 09:02:38)
- 18 (2025-01-03 (金) 09:03:21)
- 19 (2025-01-03 (金) 09:04:02)
- category: swing
folder: SingleClickCellEdit
title: JTableのセルをシングルクリックで編集する
tags: [JTable, TableCellEditor]
author: aterai
pubdate: 2007-11-19T13:45:37+09:00
description: JTableのセルをマウスでシングルクリックすると編集状態になるように設定します。
image:
Summary
JTable
のセルをマウスでシングルクリックすると編集状態になるように設定します。
Screenshot

Advertisement
Source Code Examples
DefaultCellEditor ce = (DefaultCellEditor) table.getDefaultEditor(Object.class);
ce.setClickCountToStart(1);
// ce.setClickCountToStart(2); // default
View in GitHub: Java, KotlinExplanation
上記のサンプルでは、JTable
のセルエディタを起動するのに必要なマウスクリックの回数をDefaultCellEditor#setClickCountToStart(...)
メソッドで1
回に設定しています。
edit the cell on single click
をチェックした場合、セルレンダラーも変更して文字列に下線を引くように設定- 環境やバージョンによって以下のように動作が異なる場合がある
WindowsLookAndFeel
の場合、第0
列目のセルをクリックし選択された行直下の第1
列目セル上にカーソルを置くと、その文字色がJDK 1.6.0
とJDK 1.5.0
で異なるJDK 1.5.0
で選択されたときの文字色になる?Ubuntu 7.10
、GNOME 2.20.1
、JDK 1.6.0_03
の場合、MetalLookAndFeel
とGTKLookAndFeel
で0
行目(Number.class
)に使われるセルレンダラーが異なるGTKLookAndFeel
でNumber.class
なのに左寄せになってしまう?
- 環境やバージョンによって以下のように動作が異なる場合がある
参考リンク
- DefaultCellEditor#setClickCountToStart(int) (Java Platform SE 8)
- Swing - JTable - enable cursor blink at cell with single click