【问题标题】:Is it possible to get the 'new color' in JavaFx ColorPicker?是否有可能在 JavaFx ColorPicker 中获得“新颜色”?
【发布时间】:2018-02-24 18:21:58
【问题描述】:

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

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

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

所以我想知道,是否有可能得到这个值?

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

【问题讨论】:

    标签: java events javafx colors color-picker


    【解决方案1】:

    是的,每次修改对话框中的选择时,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();
    }
    

    【讨论】:

      猜你喜欢
      • 2013-02-28
      • 1970-01-01
      • 2018-07-25
      • 2020-06-11
      • 1970-01-01
      • 2013-07-29
      • 1970-01-01
      • 1970-01-01
      • 2015-06-02
      相关资源
      最近更新 更多