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 java.util.ArrayList; public class UIBspRadioButton01 extends Application { private RadioButton rb1 = new RadioButton("RB1"); private RadioButton rb2 = new RadioButton("RB2"); private RadioButton rb3 = new RadioButton("RB3"); 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); ToggleGroup group1 = new ToggleGroup(); // javafx.scene.control.ToggleButton VBox vbox1 = new VBox(22); vbox1.setBorder(new Border( new BorderStroke(Color.GREEN, BorderStrokeStyle.SOLID, new CornerRadii(10), new BorderWidths(2))) ); vbox1.setFillWidth(true); rb1.setToggleGroup(group1); rb1.setFont(new Font("Courier New",22)); rb1.setMaxWidth(Double.POSITIVE_INFINITY); rb1.setOnAction(new EventHandler() { @Override public void handle(ActionEvent e) { rb1(); } }); vbox1.getChildren().add(rb1); vbox1.setVgrow(rb1, Priority.ALWAYS); vbox1.setMargin(rb1, new Insets(5) ); // TRBL rb2.setToggleGroup(group1); rb2.setFont(new Font("Courier New",22)); rb2.setMaxWidth(Double.POSITIVE_INFINITY); rb2.setOnAction(new EventHandler() { @Override public void handle(ActionEvent e) { rb2(); } }); vbox1.getChildren().add(rb2); vbox1.setVgrow(rb2, Priority.ALWAYS); vbox1.setMargin(rb2, new Insets(5) ); // TRBL rb3.setToggleGroup(group1); rb3.setFont(new Font("Courier New",22)); rb3.setMaxWidth(Double.POSITIVE_INFINITY); rb3.setOnAction(new EventHandler() { @Override public void handle(ActionEvent e) { rb3(); } }); vbox1.getChildren().add(rb3); vbox1.setVgrow(rb3, Priority.ALWAYS); vbox1.setMargin(rb3, new Insets(5) ); // TRBL root.getChildren().add(vbox1); root.setMargin(vbox1, new Insets(30) ); // TRBL 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, 340); stage.setTitle("UIBspRadioButton01"); stage.setScene(scene); stage.show(); } private void rb1() { System.out.println("rb1"); } private void rb2() { System.out.println("rb2"); } private void rb3() { System.out.println("rb3"); } private void calc() { StringBuilder sb = new StringBuilder(100); if (rb1.isSelected()) { sb.append("rb1 ist selektiert"); } if (rb2.isSelected()) { sb.append("rb2 ist selektiert"); } if (rb3.isSelected()) { sb.append("rb3 ist selektiert"); } errorBox(sb.toString(),"Hinweis"); } 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); } }