Swing/BooleanCellEditor のバックアップの現在との差分(No.6)
- 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
の背景色を選択色に変更します。
Screenshot
Advertisement
サンプルコード
サンプルコード
JTable table = new JTable(model) {
@Override public Component prepareEditor(TableCellEditor editor, int row, int column) {
@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;
if (c instanceof JCheckBox) {
JCheckBox b = (JCheckBox) c;
b.setBackground(getSelectionBackground());
b.setBorderPainted(true);
}
return c;
}
};
View in GitHub: Java, Kotlin解説
- 上:デフォルト
- セルをクリックして編集状態になると
CellEditor
として、背景色が白のJCheckBox
が表示される
- セルをクリックして編集状態になると
- 下:
JTable#getSelectionBackground()
-
BooleanCellEditor
として使用するJCheckBox
の背景色が常にJTable#getSelectionBackground()
になるようにJTable#prepareEditor(...)
をオーバーライド
-
解説
- 上: デフォルト
- セルをクリックして編集状態になると
CellEditor
として背景色がJTable
と同じ白色になるJCheckBox
が表示される
- セルをクリックして編集状態になると
- 下:
JTable#getSelectionBackground()
-
BooleanCellEditor
として使用するJCheckBox
の背景色が常にJTable#getSelectionBackground()
になるようにJTable#prepareEditor(...)
メソッドをオーバーライド
-