import javafx.application.Application; import javafx.geometry.Insets; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ChoiceBox; import javafx.scene.layout.VBox; public class App extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) throws Exception { ChoiceBox choicebox = new ChoiceBox<>(); choicebox.setValue("Szilva"); choicebox.getItems().add("szilva"); choicebox.getItems().add("körte"); choicebox.getItems().add("barack"); choicebox.getItems().addAll("alma", "banán", "citrom"); Button button = new Button("Mehet"); button.setOnAction(e -> { System.out.println(choicebox.getValue()); }); VBox vbox = new VBox(10); vbox.setPadding(new Insets(10, 10, 10, 10)); vbox.getChildren().addAll(choicebox, button); Scene scene = new Scene(vbox, 300, 250); primaryStage.setScene(scene); primaryStage.show(); } }