Swing/BooleanCellEditor のバックアップの現在との差分(No.3)
- バックアップ一覧
- 差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/BooleanCellEditor へ行く。
- 1 (2010-12-13 (月) 00:05:06)
- 2 (2011-05-24 (火) 02:26:32)
- 3 (2012-02-23 (木) 15:05:20)
- 4 (2012-12-27 (木) 07:51:03)
- 5 (2013-07-26 (金) 01:16:18)
- 6 (2015-01-29 (木) 15:37:32)
- 7 (2016-06-01 (水) 21:49:40)
- 8 (2017-09-14 (木) 12:05:49)
- 9 (2019-02-28 (木) 18:32:56)
- 10 (2020-12-11 (金) 18:02:51)
- 11 (2023-04-16 (日) 03:52:16)
- 追加された行はこの色です。
- 削除された行はこの色です。
TITLE:JTableが使用するBooleanCellEditorの背景色を変更 #navi(../) RIGHT:Posted by [[aterai]] at 2010-09-06 *JTableが使用するBooleanCellEditorの背景色を変更 [#t541c708] JTableがデフォルトで使用する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: https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTIJ0rZk-I/AAAAAAAAASU/JvYohArvFpU/s800/BooleanCellEditor.png --- * 概要 [#summary] `JTable`がデフォルトで使用する`BooleanCellEditor`の背景色を選択色に変更します。 -&jnlp; -&jar; -&zip; #download(https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTIJ0rZk-I/AAAAAAAAASU/JvYohArvFpU/s800/BooleanCellEditor.png) //#screenshot #ref(http://lh5.ggpht.com/_9Z4BYR88imo/TQTIJ0rZk-I/AAAAAAAAASU/JvYohArvFpU/s800/BooleanCellEditor.png) **サンプルコード [#ve611f4c] #code{{ * サンプルコード [#sourcecode] #code(link){{ 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; } }; }} **解説 [#ybbf81d6] -上:デフォルト --セルをクリックして編集状態になるとCellEditorとして、背景色が白のJCheckBoxが表示される -下:JTable#getSelectionBackground() --BooleanCellEditorとして使用するJCheckBoxの背景色が常にJTable#getSelectionBackground()になるようにJTable#prepareEditor(...)をオーバーライド * 解説 [#explanation] - 上: デフォルト -- セルをクリックして編集状態になると`CellEditor`として背景色が`JTable`と同じ白色になる`JCheckBox`が表示される - 下: `JTable#getSelectionBackground()` -- `BooleanCellEditor`として使用する`JCheckBox`の背景色が常に`JTable#getSelectionBackground()`になるように`JTable#prepareEditor(...)`メソッドをオーバーライド //**参考リンク **コメント [#d9435978] * 参考リンク [#reference] [https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/JTable.html#prepareEditor-javax.swing.table.TableCellEditor-int-int- JTable#prepareEditor(...) (Java Platform SE 8)] * コメント [#comment] #comment - KBD{Ctrl}キーを押しながら選択されている行にある`JCheckBox`をマウスで選択するとリリースするまで`JCheckBox`の背景色が残る、または`NimbusLookAndFeel`から別の`LookAndFeel`に変更すると選択色が残るなどの問題に対応。 -- &user(aterai); &new{2012-02-23 (木) 15:05:20}; #comment