Swing/BooleanCellEditor のバックアップ(No.9)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/BooleanCellEditor へ行く。
- category: swing
folder: BooleanCellEditor
title: JTableが使用するBooleanCellEditorの背景色を変更
tags: [JTable, TableCellEditor, JCheckBox]
author: aterai
pubdate: 2010-09-06T11:51:11+09:00
description: JTableがデフォルトで使用するBooleanCellEditorの背景色を選択色に変更します。
image:
概要
JTable
がデフォルトで使用するBooleanCellEditor
の背景色を選択色に変更します。
サンプルコード
JTable table = new JTable(model) {
@Override public Component prepareEditor(TableCellEditor editor, int row, int column) {
Component c = super.prepareEditor(editor, row, column);
if (c instanceof JCheckBox) {
JCheckBox b = (JCheckBox) c;
b.setBackground(getSelectionBackground());
b.setBorderPainted(true);
}
return c;
}
};
view all解説
- 上: デフォルト
- セルをクリックして編集状態になると
CellEditor
として、背景色が白のJCheckBox
が表示される
- セルをクリックして編集状態になると
- 下:
JTable#getSelectionBackground()
BooleanCellEditor
として使用するJCheckBox
の背景色が常にJTable#getSelectionBackground()
になるようにJTable#prepareEditor(...)
メソッドをオーバーライド
参考リンク
JTable#prepareEditor(...) (Java Platform SE 8)