NetBeans平台:如何以编程方式设置NetBeans GUI组件的样式? [英] NetBeans Platform: How to style the NetBeans GUI components programmatically?

查看:105
本文介绍了NetBeans平台:如何以编程方式设置NetBeans GUI组件的样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用NetBeans Platform和JavaFX 11对胖客户端进行编程,其中一项要求是为应用程序提供默认的深色主题模式.因此,如果我的GUI应用程序的用户按下深色模式按钮,则该应用程序的GUI会变为深色样式.

I have to program a fat client using NetBeans Platform and JavaFX 11. One of the requirements is to offer a default and dark theme mode for the application. So if the user of my GUI application press the dark mode button, the application's GUI changes to the dark style.

虽然对我来说如何设置JFX组件的样式(通过CSS文件)很明显,但是CSS文件对菜单栏等NetBeans Platform的组件没有影响.例如,场景对象中的JavaFX组件具有深色样式,但NetBeans菜单栏仍然较亮.

While its obvious for me how to style the JFX components (via a CSS file), the CSS file doesn't has an impact on the NetBeans Platform's components like the menu bar. For instance the JavaFX components inside a scene object got a dark styling, but the NetBeans menu bar is still light.

如何以编程方式更改NetBeans Platform组件的样式(就像您在Web开发中使用CSS或在JavaFX中使用CSS支持一样)?

How its possible to change the style of NetBeans Platform's components programmatically (just as you would have done with CSS in web development or with the CSS support in JavaFX)?

推荐答案

平台上有一个嵌入式的深色LAF(至少在我使用的NB12中),称为FlatDarkLaf,看起来不错.

There is an embedded dark LAF in the platform (at least in NB12 which I use) called FlatDarkLaf, it looks nice.

要使用它,您需要在ModuleInstall子类的validate()方法中添加以下代码,以便在启动过程中尽早完成.

In order to use it, you need to add the following code in the validate() method of a ModuleInstall subclass, so that it's done very early during the startup process.

NbPreferences.root().node("laf").put("laf", "com.formdev.flatlaf.FlatDarkLaf");
UIManager.installLookAndFeel(new UIManager.LookAndFeelInfo("FlatLaf Dark", latDarkLaf.class.getName()));  

要切换回默认主题,请执行以下操作:

To switch back to the default theme:

NbPreferences.root().node("laf").remove("laf");

我不知道不重新启动即可更改LAF的(简单)方法.

I'm not aware of a (simple) way of changing the LAF without restarting.

有关更完整的示例代码,请在 GitHub 上查看我的应用程序JJazzLab-X. ,在UISettings Netbeans模块中.

For a more complete sample code have a look at my application JJazzLab-X on GitHub, in the UISettings Netbeans module.

这篇关于NetBeans平台:如何以编程方式设置NetBeans GUI组件的样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆