我应该设置什么外观组件来更改 TitledBorder 的文本颜色?

发布于 2024-08-23 16:19:00 字数 425 浏览 6 评论 0原文

我的 Swing 应用程序中有一组单选按钮,它们周围有一个边框,如下所示:

radioButtonPanel.setBorder( new CompoundBorder ( 
    BorderFactory.createTitledBorder( " Input Data " ), padBorder ) );

我们的应用程序支持两种外观和感觉:浅色和深色。在两者之间切换时,边框颜色本身似乎会正确更改颜色,但文本不会。对于我的一生,我无法弄清楚我应该设置颜色的组件的名称是什么。 createTitledBorder() 的文档说它使用默认的外观和感觉,但我不确定它在哪里提取默认值。我以为是 Panel.foreground,但事实并非如此,而且其他看起来都不太正确。

有人知道我需要在这里设置哪个外观和感觉组件吗?

I have a group of radio buttons in my Swing application that have a border built around them as follows:

radioButtonPanel.setBorder( new CompoundBorder ( 
    BorderFactory.createTitledBorder( " Input Data " ), padBorder ) );

Our application supports two look and feels, a light and a dark one. When switching between the two, the border color itself appears to change colors correctly, but the text does not. For the life of me, I can't figure out what the name of the component is I should be setting the color of. The documentation for createTitledBorder() says it uses the default look and feel, but I'm unsure where it's pulling its default. I thought it was the Panel.foreground, but that's not it and nothing else seems to look quite right.

Does anybody know which look and feel component I need to be setting here?

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

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

发布评论

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

评论(2

岛徒 2024-08-30 16:19:00

您可以在 TitledBorder 实例上设置标题颜色,或使用将标题颜色作为参数的构造函数创建一个实例。

TitledBorder javadoc 还指出“外观中的“TitledBorder.titleColor”属性用作默认值。您可以按如下方式覆盖它:

UIManager.getDefaults().set("TitledBorder.titleColor", Color.RED);

You can set the title colour on a TitledBorder instance or create one using a constructor that takes the title colour as an argument.

The TitledBorder javadoc also states that "TitledBorder.titleColor" property from the look and feel is used as the default. You can override this as follows:

UIManager.getDefaults().set("TitledBorder.titleColor", Color.RED);
聆听风音 2024-08-30 16:19:00

您无需致电,而是

UIManager.getDefaults().set("TitledBorder.titleColor", Color.RED);

需要致电

UIManager.put("TitledBorder.titleColor", Color.RED);

Instead of calling

UIManager.getDefaults().set("TitledBorder.titleColor", Color.RED);

you will need to call

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