JavaFX-2 ߝ设置几种样式

发布于 2024-12-28 07:20:32 字数 611 浏览 2 评论 0原文

我正在尝试更改 javafx-2 中 TextArea 的背景和文本颜色。

    myComponent = new TextArea();
    myComponent.setStyle("-fx-text-fill : white;");
    myComponent.setStyle("-fx-background-color : black;");
    myComponent.setStyle("-fx-font : " + GUIConstants.SysResponseFont.getName());
    myComponent.setStyle("-fx-font-family : " + GUIConstants.SysResponseFont.getFamily());
    myComponent.setStyle("-fx-font-size : " + GUIConstants.SysResponseFont.getSize());
    myComponent.setStyle("-fx-font-weight : " + GUIConstants.SysResponseFont.getStyle());

此 TextArea 中既没有设置颜色也没有设置字体。我必须使用不同的方法吗?

I'm trying to change the background and text-color of a TextArea in javafx-2.

    myComponent = new TextArea();
    myComponent.setStyle("-fx-text-fill : white;");
    myComponent.setStyle("-fx-background-color : black;");
    myComponent.setStyle("-fx-font : " + GUIConstants.SysResponseFont.getName());
    myComponent.setStyle("-fx-font-family : " + GUIConstants.SysResponseFont.getFamily());
    myComponent.setStyle("-fx-font-size : " + GUIConstants.SysResponseFont.getSize());
    myComponent.setStyle("-fx-font-weight : " + GUIConstants.SysResponseFont.getStyle());

Neither the colors nor the font gets set in this TextArea. Do I have to use a different approach?

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

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

发布评论

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

评论(1

倾城月光淡如水﹏ 2025-01-04 07:20:32

后面的 setStyle() 会覆盖前面的。下一个代码将设置几种样式:

    myComponent.setStyle("-fx-text-fill: white;"+
    "-fx-background-color: black;"+
    "-fx-font: Courier New;"+
    "-fx-font-family: Courier New;"+
    "-fx-font-weight: bold;"+
    "-fx-font-size: 30;");

我想对于您的代码片段来说,它将是:

myComponent = new TextArea();
myComponent.setStyle(
    "-fx-text-fill: white;"+
    "-fx-background-color: black;"+
    "-fx-font: " + GUIConstants.SysResponseFont.getName()+ ";" +
    "-fx-font-family: " + GUIConstants.SysResponseFont.getFamily()+ ";" +
    "-fx-font-size: " + GUIConstants.SysResponseFont.getSize()+ ";" +
    "-fx-font-weight: " + GUIConstants.SysResponseFont.getStyle());        

注意行末尾的 ; 符号。

Your latter setStyle() overrides previous ones. Next code will set several styles:

    myComponent.setStyle("-fx-text-fill: white;"+
    "-fx-background-color: black;"+
    "-fx-font: Courier New;"+
    "-fx-font-family: Courier New;"+
    "-fx-font-weight: bold;"+
    "-fx-font-size: 30;");

I guess for your code snippet it would be:

myComponent = new TextArea();
myComponent.setStyle(
    "-fx-text-fill: white;"+
    "-fx-background-color: black;"+
    "-fx-font: " + GUIConstants.SysResponseFont.getName()+ ";" +
    "-fx-font-family: " + GUIConstants.SysResponseFont.getFamily()+ ";" +
    "-fx-font-size: " + GUIConstants.SysResponseFont.getSize()+ ";" +
    "-fx-font-weight: " + GUIConstants.SysResponseFont.getStyle());        

Note the ; signs at the end of the lines.

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