import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.Stage; import javafx.scene.text.TextAlignment; import javafx.scene.text.Font; import javafx.geometry.Pos; import javafx.geometry.Insets; import javafx.scene.layout.Border; import javafx.scene.layout.BorderStroke; import javafx.scene.layout.BorderStrokeStyle; import javafx.scene.layout.BorderWidths; import javafx.scene.paint.Color; import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.event.Event; import javafx.collections.*; public class UIBspSpinner02 extends Application { private Spinner spPizza = new Spinner(); private CheckBox chkMitZwiebel = new CheckBox("Mit Zwiebeln") ; private CheckBox chkMitMais = new CheckBox("Mit Mais") ; private TextField tErg = new TextField("") ; private Button bnOk = new Button("Ok") ; private Button bnEsc = new Button("Esc") ; @Override public void start(Stage stage) { VBox root = new VBox(22); root.setAlignment(Pos.CENTER); root.setFillWidth(true); ObservableList pizzas = FXCollections.observableArrayList( "Käse", "Käse Schinken", "Hawai", "Salami / Schinken", "Vegetarisch", "Peperoni", "Vier Jahreszeiten", "Ei, ExtraKäse"); SpinnerValueFactory valueFactory = new SpinnerValueFactory.ListSpinnerValueFactory(pizzas); // Default value valueFactory.setValue("Hawaii"); spPizza.setValueFactory(valueFactory); spPizza.setStyle("-fx-font: 22px \"Serif\";"); HBox hbox = createChoiceBoxComboBoxSpinner(spPizza , "Name der Pizza"); root.getChildren().add(hbox); hbox = createButtonBase(chkMitZwiebel); root.getChildren().add(hbox); hbox = createButtonBase(chkMitMais ); root.getChildren().add(hbox); hbox = createTextInputControl(tErg, "Ergebnis"); root.getChildren().add(hbox); FlowPane boxpane = new FlowPane(20,20); boxpane.setAlignment(Pos.CENTER); boxpane.setMaxWidth(Double.POSITIVE_INFINITY); root.getChildren().add(boxpane); bnOk.setFont(new Font("Courier New",22)); bnOk.setMaxWidth(Double.POSITIVE_INFINITY); bnOk.setOnAction(e->calc()); boxpane.getChildren().add(bnOk); boxpane.setMargin(bnOk, new Insets(0, 10, 0, 10) ); // TRBL bnEsc.setFont(new Font("Courier New",22)); bnEsc.setMaxWidth(Double.POSITIVE_INFINITY); bnEsc.setOnAction(e->Platform.exit()); boxpane.getChildren().add(bnEsc); boxpane.setMargin(bnEsc, new Insets(0, 10, 0, 10) ); // TRBL Scene scene= new Scene(root, 660, 400); stage.setTitle("UIBspSpinner02"); stage.setScene(scene); stage.show(); } private HBox createTextInputControl(TextInputControl control, String caption) { HBox hbox = new HBox(22); hbox.setFillHeight(true); hbox.setMaxWidth(Double.POSITIVE_INFINITY); Label label = new Label(caption) ; label.setFont(new Font("Courier New",22)); hbox.getChildren().add(label); hbox.setMargin(label, new Insets(5, 0, 0, 10) ); // TRBL control.setFont(new Font("Courier New",22)); control.setMaxWidth(Double.POSITIVE_INFINITY); hbox.getChildren().add(control); hbox.setHgrow(control, Priority.ALWAYS); hbox.setMargin(control, new Insets(0, 10, 0, 10) ); // TRBL return hbox; } private HBox createChoiceBoxComboBoxSpinner(Control control, String caption) { HBox hbox = new HBox(22); hbox.setFillHeight(true); hbox.setMaxWidth(Double.POSITIVE_INFINITY); Label label = new Label(caption) ; label.setFont(new Font("Courier New",22)); hbox.getChildren().add(label); hbox.setMargin(label, new Insets(5, 0, 0, 10) ); // TRBL // control.setFont(new Font("Courier New",22)); // gibt es nicht ?? control.setMaxWidth(Double.POSITIVE_INFINITY); hbox.getChildren().add(control); hbox.setHgrow(control, Priority.ALWAYS); hbox.setMargin(control, new Insets(0, 10, 0, 10) ); // TRBL return hbox; } private HBox createButtonBase(ButtonBase control) { HBox hbox = new HBox(22); hbox.setFillHeight(true); hbox.setMaxWidth(Double.POSITIVE_INFINITY); control.setFont(new Font("Courier New",22)); control.setMaxWidth(Double.POSITIVE_INFINITY); hbox.getChildren().add(control); hbox.setHgrow(control, Priority.ALWAYS); hbox.setMargin(control, new Insets(0, 10, 0, 10) ); // TRBL return hbox; } private void calc() { StringBuilder sb = new StringBuilder(100); String pizza = (String)spPizza.getValue(); if (pizza==null) { errorBox("Bitte geben Sie einen Pizzanamen ein","Hinweis"); return; } sb.append(pizza); sb.append(": "); if (chkMitZwiebel.isSelected()) { sb.append(", mit Zwiebeln "); } if (chkMitMais.isSelected()) { sb.append(", mit Mais "); } tErg.setText(sb.toString()); } public void errorBox( String message, String title) { Dialog alert = new Alert(Alert.AlertType.ERROR,message); alert.setTitle(title); alert.setHeaderText(title); alert.setResizable(true); alert.show(); // a.setContentText(content); } // ErrorBox public static void main(String[] argv) { launch(argv); } }