JTableが使用するBooleanCellEditorの背景色を変更
Total: 8116, Today: 1, Yesterday: 0
Posted by aterai at
Last-modified:
Summary
JTableがデフォルトで使用するBooleanCellEditorの背景色を選択色に変更します。
Screenshot

Advertisement
Source Code Examples
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 in GitHub: Java, KotlinDescription
- 上: デフォルト
- セルをクリックして編集状態になると
CellEditorとして背景色がJTableと同じ白色になるJCheckBoxが表示される
- セルをクリックして編集状態になると
- 下:
JTable#getSelectionBackground()BooleanCellEditorとして使用するJCheckBoxの背景色が常にJTable#getSelectionBackground()になるようにJTable#prepareEditor(...)メソッドをオーバーライド
Reference
JTable#prepareEditor(...) (Java Platform SE 8)