整个应用程序的JavaFx CSS [英] JavaFx css for whole application

查看:114
本文介绍了整个应用程序的JavaFx CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在为我们的应用程序使用自定义CSS问题。到目前为止,我们一直使用变通方法来应用自定义的CSS,但其余部分保持摩登风格。

we are struggling on a problem with custom css for our application. Until now we used workaround to apply our custom css but keep modena style for the rest.

StyleManager.getInstance().addUserAgentStylesheet(css);

在8u40 Java更新中,此行为受到限制,并且不再起作用。将样式表分别设置到所有场景是很疯狂的事情,通过

In 8u40 java update this behavior was however restricted and is no longer working. Setting stylesheets to all scenes separately is madness, setting custom stylesheet via

Application.setUserAgentStylesheet(css);

可以工作,但是没有达到我们的预期-Modena样式表已被自定义替换,因此许多控件根本没有样式。
我们找到了另一个解决方法:将整个modena文件夹复制到我们的项目中,将自定义的css样式添加到modena.css中,(非常重要!)将modena.css重命名为其他名称,例如modenaB.css。在JavaFx源代码样式表中进行了比较,如果名称保持不变,即使提供了不同的url,也将使用原始的Modena。

works but not as we intended - modena stylesheet is replaced by custom so many controls are not styled at all. We found another workaround: copy whole modena folder to our project, add our custom css styles to modena.css and (very important!) rename modena.css to something else, for example modenaB.css. In JavaFx source code stylesheet is compared and if name remains the same, original modena is used eventhough different url was provided.

我的问题是,有没有更好的应用方法一个自定义样式表,而应用程序初始化将在所有场景中用于整个应用程序,同时为所有未覆盖的控件保留默认的Modena样式?

My question is, is there some better way to apply one custom stylesheet while application initialization which will be used through whole application in all scenes while keeping default modena styles for all not overriden controls?

推荐答案

最简单的方法是在用户代理样式表中添加css文件。

The easiest way is to add your css file in User Agent Stylesheet.

@Override
public void start(Stage primaryStage) {
    // ...
    Application.setUserAgentStylesheet(Application.STYLESHEET_MODENA);
    StyleManager.getInstance().addUserAgentStylesheet("example.css");
    // ...
}

<一个href = http://www.guigarage.com/2013/03/global-stylesheet-for-your-javafx-application/ rel = nofollow noreferrer> GuiGarage 。

这篇关于整个应用程序的JavaFx CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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