如何在javafx中更改窗格的颜色? [英] How to change the color of pane in javafx?

查看:287
本文介绍了如何在javafx中更改窗格的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改用户从String获得的Pane的颜色. 如何在窗格中将此String设置为背景颜色?

I want to change the color of a Pane which I get as a String from user. How can I set this String as a background color in my pane?

代码:

colorField.setOnKeyTyped(new EventHandler<KeyEvent>() {
    @Override
    public void handle(KeyEvent t) {
        color = colorField.getText();
    }
});

推荐答案

如果您真的只是想知道如何完成特定的事情,我建议以下几点:

If you really just want to know how to accomplish that particular thing, I'd suggest the following:

设置节点 CSS ,使用 hexacolor 由用户输入:

Set the Nodes' CSS like this, using the hexacolor that was entered by the user:

String enteredByUser = "abcdef";
yournode.setStyle("-fx-background-color: #" + enteredByUser);

如果您想了解更多信息,请更具体地回答问题,并提供一些代码示例.

If you want to know more please be more specific with you questions and provide some code samples.

由于您用"javafx-8"标记了这个问题,因此我还将提供该代码示例(仅适用于javafx 8):

Since you tagged this question with 'javafx-8' i'll provide that code example as well(only works in javafx 8):

yournode.setBackground(new Background(new BackgroundFill(Color.web("#" + enteredByUser), CornerRadii.EMPTY, Insets.EMPTY)));

希望有帮助, 劳伦兹

这篇关于如何在javafx中更改窗格的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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