How to change the color of pane in javafx?

 ̄綄美尐妖づ 提交于 2019-12-10 01:30:11

问题


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?

Code:

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

回答1:


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

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.

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)));

Hope it helps, Laurenz



来源:https://stackoverflow.com/questions/22841000/how-to-change-the-color-of-pane-in-javafx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!