Jos*_*hua 2 java swing jtable colors look-and-feel
所以我有自定义的 CellEditors 和 CellRenderers,尽管我正在做
component.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
component.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
component.setOpaque(true);
Run Code Online (Sandbox Code Playgroud)
在我的 getTableCellRendererCompoent 中,颜色仅与其他每一行匹配,因为我尝试过的大多数外观和感觉似乎都在交替它们。如何以与表的其余部分相匹配的方式提取颜色值?我也非常希望能够制作漂亮的边框来匹配来自 DefaultTableCellRenderer 的渲染器。
我试图剖析 DefaultTableCellRenderer,但在试图追踪这个 UI 对象时迷失了方向。我是否只需要从 UIManager 中提取正确的属性?正确方向的引导将不胜感激。
谢谢大家,这个网站很棒。约书亚
小智 6
是的,您应该使用 Swing 调色板颜色。例如:
final Color tableBackground = javax.swing.UIManager.getDefaults().getColor("Table.background");
Run Code Online (Sandbox Code Playgroud)
以下是表格的颜色键值:
或者,您也可以使用系统颜色。例如:
正常背景:
SystemColor.window
选定背景:SystemColor.textHighlight
正常前景:SystemColor.text
选定前景:SystemColor.textText