java - 获取 TableCellEditor 颜色以匹配外观和感觉

标签 java swing colors jtable look-and-feel

所以我有自定义的 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/

相关文章:

java - 如何使用 RestTemplate 反序列化嵌套列表?

java - 如何更改其他框架中的 setInminated jProgressbar

java - 如何将类对象传递给另一个使用 super() 的类;

java - 更改启用 JTextField 的背景颜色

java - 可以显示设备摄像头的实时输出吗?

java - 通过 keyPressed 在 JLabel 中一个一个地更改值

java - spring-cloud-config-aws-kms NoUniqueBeanDefinitionException : defaultTextEncryptor, kmsTextEncryptor

java - JComboBox 选择更改

swift - 如何快速将 UIColor 类型的值转换为 Uint

CSS 新手问题——标题没有采用指定的颜色