gpt4 book ai didi

java - JavaFx ColorPicker 中是否可以获取 'new color' ?

转载 作者:行者123 更新时间:2023-12-02 02:18:07 25 4
gpt4 key购买 nike

我正在尝试从 ColorPicker 获取“新颜色”值(图像中的“nouvelle couleur”,因为它是法国的)。

This is what I'm talking about

colorPicker.setOnAction((ActionEvent e) -> {
text.setFill(colorPicker.getValue());
});

当您为 ColorPicker 设置 EventHandler 时,它仅在您关闭 ColorPicker 时返回 ColorPicker 的值。

所以我想知道,是否可以获得这个值?

抱歉,如果有任何错误,英语不是我的母语。

最佳答案

是的,每次修改对话框中的选择时,ColorPicker 控件中的 valueProperty() 都会更新。仅当您取消更改时,更改才会被撤销。

因此,您只需向该属性添加一个监听器或根据需要绑定(bind)它。

@Override
public void start(Stage primaryStage) {
ColorPicker picker = new ColorPicker(Color.ALICEBLUE);
Text text = new Text("Color Picker");
VBox root = new VBox(10, text, picker);
root.setAlignment(Pos.CENTER);

text.fillProperty().bind(picker.valueProperty());

Scene scene = new Scene(root, 300, 250);

primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}

color picker

关于java - JavaFx ColorPicker 中是否可以获取 'new color' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48966170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com