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

发布于 2024-07-20 07:20:01 字数 590 浏览 5 评论 0原文

因此,我有自定义的 CellEditors 和 CellRenderers,尽管我在 getTableCellRendererCompoent 中进行操作

component.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
component.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
component.setOpaque(true);

,但颜色仅与其他每一行匹配,因为我尝试过的大多数外观和感觉似乎都在交替它们。 如何以与表的其余部分相匹配的方式提取颜色值? 我也非常希望能够制作漂亮的边框来匹配来自 DefaultTableCellRenderer 的渲染器。

我试图剖析 DefaultTableCellRenderer,但在试图追踪这个 UI 对象时迷失了方向。 我是否只需要从 UIManager 中提取正确的属性? 正确方向的引导将不胜感激。

谢谢大家,这个网站很棒。 约书亚

So I have custom CellEditors and CellRenderers and although I am doing

component.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
component.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
component.setOpaque(true);

in my getTableCellRendererCompoent, the colors only match on every OTHER row, since most of hte look and feels I've tried seem to alternate them. How can I pull the color values in a way that they'll match whatever the rest of the table looks like? I'd also really like to be able to make nice borders to match the renderers descended from DefaultTableCellRenderer.

I've tried to dissect the DefaultTableCellRenderer, and I got lost trying to track down this UI object. Do I just need the right properties to pull from the UIManager? A lead in the right direction will be much appreciated.

Thanks all, this site rocks.
Joshua

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我为君王 2024-07-27 07:20:01

是的,您应该使用 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

或者,您也可以使用系统颜色 。 例如:

普通背景: SystemColor.window
选定的背景: SystemColor.textHighlight
普通前景: SystemColor.text
选定的前景: SystemColor.textText

Yes, you should use the Swing palette colors. For example:

final Color tableBackground = javax.swing.UIManager.getDefaults().getColor("Table.background");

Here's the color key values for tables:

  • 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

Alternatively, you could also use the system colors. For example:

Normal background: SystemColor.window
Selected background: SystemColor.textHighlight
Normal foreground: SystemColor.text
Selected foreground: SystemColor.textText

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文