4 Replies Latest reply: Nov 6, 2013 8:10 AM by Nikolai Varankine RSS

    How to change the value of a color picker?

    FXit
      Hi *,

      I am currently working on a small project and I would like to use the colorpicker. When I initialize the colorpicker the, the widget is updated and shows the correct color, but when I try to change the value at runtime, nothing happens. Did I miss something?

      Many thanks
       
      package javafx.tests.colorpicker;
      
      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.geometry.Insets;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.ColorPicker;
      import javafx.scene.layout.StackPane;
      import javafx.scene.layout.VBox;
      import javafx.scene.paint.Color;
      import javafx.stage.Stage;
      
      public class ColorPickerChangeColor extends Application {
      
           public static void main(String[] args) {
                Application.launch(args);
           }
      
           @Override
           public void start(Stage stage) throws Exception {
      
                VBox vbox = new VBox();
                vbox.setPadding(new Insets(10));
                vbox.setSpacing(10);
                Button button = new Button("Press me.");
                final ColorPicker colorpicker = new ColorPicker(Color.BLUE);
      
                button.setOnAction(new EventHandler<ActionEvent>() {
                     @Override
                     public void handle(ActionEvent arg0) {
                          colorpicker.setValue(Color.YELLOW);
                          System.out.println("Set color of the picker to yellow.");
                     }
                });
      
                vbox.getChildren().add(colorpicker);
                vbox.getChildren().add(button);
      
                StackPane root = new StackPane();
      
                root.getChildren().add(vbox);
                stage.setTitle("ColorPicker");
                Scene scene = new Scene(root, 200, 200);
      
                stage.setScene(scene);
                stage.show();
      
           }
      }
      Edited by: 963445 on Jan 3, 2013 12:23 PM