Well, in my program I have a datePicker and a colorpicker, what I want to do is that when I press a button, I will be shown the value of the selected color and the selected date.
Well, in my program I have a datePicker and a colorpicker, what I want to do is that when I press a button, I will be shown the value of the selected color and the selected date.
You can leave us your code. anyway I leave an example of interacting with colorpicker and datePicker in a button event.
package ejemplo;
import java.time.LocalDate;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ColorPicker;
import javafx.scene.control.DatePicker;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Ejemplo extends Application {
@Override
public void start(Stage primaryStage) {
DatePicker datepicker = new DatePicker(LocalDate.now());
datepicker.setTranslateY(-70);
ColorPicker colorpicker = new ColorPicker();
colorpicker.setTranslateY(-40);
Button btn = new Button();
btn.setText("cambiar color y texto");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
btn.setTextFill(colorpicker.getValue());
btn.setText(datepicker.getValue().toString());
}
});
StackPane root = new StackPane();
root.getChildren().addAll(btn,datepicker,colorpicker);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("color y fecha ");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
the output (changes the text and color of the button according to what is selected in colorpicker and datepicker ).