如何在javafx中更改窗格的颜色? [英] How to change the color of pane in 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:
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屋!