所以我有自定义的 CellEditors 和 CellRenderers,尽管我正在这样做
component.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
component.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
component.setOpaque(true);
在我的 getTableCellRendererCompoent 中,颜色仅与其他每一行匹配,因为我尝试过的大多数外观和感觉似乎都在交替它们。如何以与表的其余部分相匹配的方式提取颜色值?我也非常希望能够制作漂亮的边框来匹配来自 DefaultTableCellRenderer 的渲染器。
我尝试剖析 DefaultTableCellRenderer,但在尝试追踪此 UI 对象时迷失了方向。我是否只需要从 UIManager 中提取正确的属性?非常感谢朝正确方向的引导。
谢谢大家,这个网站很棒。 约书亚
最佳答案
是的,您应该使用 Swing 调色板颜色。例如:
final Color tableBackground = javax.swing.UIManager.getDefaults().getColor("Table.background");
以下是表格的颜色键值:
- Table.background Table.dropLineColor
- Table.dropLineShortColor
- Table.focusCellBackground
- Table.focusCellForeground
- Table.foreground Table.gridColor
- Table.selectionBackground
- Table.selectionForeground
- Table.sortIconColor
- TableHeader.background
- TableHeader.focusCellBackground
- TableHeader.foreground
或者,您也可以使用 system colors 。例如:
Normal background:
SystemColor.window
Selected background:SystemColor.textHighlight
Normal foreground:SystemColor.text
Selected foreground:SystemColor.textText
关于java - 获取 TableCellEditor 颜色以匹配外观和感觉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/862677/