是否有可能获得';新颜色&x27;在JavaFXColorPicker中?

是否有可能获得';新颜色&x27;在JavaFXColorPicker中?,java,events,javafx,colors,color-picker,Java,Events,Javafx,Colors,Color Picker,我试图从一个颜色选择器中获取“新颜色”值(“在我的图像中是nouvelle couleur”,因为它是法语) 为ColorPicker设置EventHandler时,它仅在关闭ColorPicker时返回其值 所以我想知道,有可能得到这个值吗 抱歉,如果有任何错误,英语不是我的母语。是的,每次修改对话框中的选择时,ColorPicker控件中的valueProperty()都会更新。只有在取消更改时,才会将其退出 因此,您只需要向该属性添加一个侦听器,或者根据需要绑定它 @Override p

我试图从一个颜色选择器中获取“新颜色”值(“在我的图像中是nouvelle couleur”,因为它是法语)

为ColorPicker设置EventHandler时,它仅在关闭ColorPicker时返回其值

所以我想知道,有可能得到这个值吗


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

是的,每次修改对话框中的选择时,ColorPicker控件中的
valueProperty()
都会更新。只有在取消更改时,才会将其退出

因此,您只需要向该属性添加一个侦听器,或者根据需要绑定它

@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();
}

是,每次修改对话框中的选择时,ColorPicker控件中的
valueProperty()
都会更新。只有在取消更改时,才会将其退出

因此,您只需要向该属性添加一个侦听器,或者根据需要绑定它

@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();
}