Example usage for javafx.scene.control RadioButton setToggleGroup

List of usage examples for javafx.scene.control RadioButton setToggleGroup

Introduction

In this page you can find the example usage for javafx.scene.control RadioButton setToggleGroup.

Prototype

public final void setToggleGroup(ToggleGroup value) 

Source Link

Usage

From source file:Main.java

private static RadioButton createRadioButton(final String text, final ToggleGroup toggleGroup,
        final boolean selected) {
    final RadioButton radioButton = new RadioButton(text);
    radioButton.setToggleGroup(toggleGroup);
    radioButton.setSelected(selected);/*from   ww w  .  ja  va2 s . c  o m*/

    return radioButton;
}

From source file:Main.java

@Override
public void start(Stage stage) {
    HBox root = new HBox();
    Scene scene = new Scene(root, 300, 150);
    stage.setScene(scene);//from w ww  . j a  v  a  2  s  .co m
    stage.setTitle("");

    ToggleGroup group = new ToggleGroup();
    RadioButton button1 = new RadioButton("select first");
    button1.setToggleGroup(group);
    button1.setSelected(true);
    RadioButton button2 = new RadioButton("select second");
    button2.setToggleGroup(group);

    root.getChildren().add(button1);
    root.getChildren().add(button2);

    scene.setRoot(root);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setWidth(250);/*w w  w. java 2s  . c  o m*/
    stage.setHeight(150);

    final ToggleGroup group = new ToggleGroup();

    RadioButton rb1 = new RadioButton("A");
    rb1.setToggleGroup(group);
    rb1.setUserData("A");

    RadioButton rb2 = new RadioButton("B");
    rb2.setToggleGroup(group);
    rb2.setUserData("B");

    RadioButton rb3 = new RadioButton("C");
    rb3.setToggleGroup(group);
    rb3.setUserData("C");

    group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
        public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) {
            if (group.getSelectedToggle() != null) {
                System.out.println(group.getSelectedToggle().getUserData().toString());
            }
        }
    });

    HBox hbox = new HBox();
    VBox vbox = new VBox();

    vbox.getChildren().add(rb1);
    vbox.getChildren().add(rb2);
    vbox.getChildren().add(rb3);
    vbox.setSpacing(10);

    hbox.getChildren().add(vbox);
    hbox.setSpacing(50);
    hbox.setPadding(new Insets(20, 10, 10, 20));

    ((Group) scene.getRoot()).getChildren().add(hbox);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Radio Button Sample");
    stage.setWidth(250);/*from  w ww  .j a va  2 s .c  o m*/
    stage.setHeight(150);

    final ToggleGroup group = new ToggleGroup();

    RadioButton rb1 = new RadioButton("A");
    rb1.setToggleGroup(group);
    rb1.setUserData("A");

    RadioButton rb2 = new RadioButton("B");
    rb2.setToggleGroup(group);
    rb2.setUserData("B");

    RadioButton rb3 = new RadioButton("C");
    rb3.setToggleGroup(group);
    rb3.setUserData("C");

    group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
        public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) {
            if (group.getSelectedToggle() != null) {
                System.out.println(group.getSelectedToggle().getUserData().toString());
            }
        }
    });

    HBox hbox = new HBox();
    VBox vbox = new VBox();

    vbox.getChildren().add(rb1);
    vbox.getChildren().add(rb2);
    vbox.getChildren().add(rb3);
    vbox.setSpacing(10);

    hbox.getChildren().add(vbox);
    hbox.setSpacing(50);
    hbox.setPadding(new Insets(20, 10, 10, 20));

    ((Group) scene.getRoot()).getChildren().add(hbox);
    stage.setScene(scene);
    stage.show();
}

From source file:de.pixida.logtest.designer.automaton.AutomatonNode.java

private RadioButton createRadioButtonForType(final Type aType, final String title,
        final ToggleGroup toggleGroup) {
    final RadioButton result = new RadioButton(title);
    result.setToggleGroup(toggleGroup);
    result.setSelected(this.type == aType);
    result.setOnAction(event -> {//from  ww  w  . j  a  v a2s.  com
        this.setType(aType);
        this.getGraph().handleChange();
    });
    return result;
}

From source file:de.pixida.logtest.designer.logreader.LogReaderEditor.java

public VBox createRunForm() {
    // CHECKSTYLE:OFF Yes, we are using lots of constants here. It does not make sense to name them using final variables.
    final VBox lines = new VBox();
    lines.setSpacing(10d);//www.j  a v a2 s . c om
    final HBox inputTypeLine = new HBox();
    inputTypeLine.setSpacing(30d);
    final ToggleGroup group = new ToggleGroup();
    final RadioButton inputTypeText = new RadioButton("Paste/Enter text");
    inputTypeText.setToggleGroup(group);
    final RadioButton inputTypeFile = new RadioButton("Read log file");
    inputTypeFile.setToggleGroup(group);
    inputTypeLine.getChildren().add(inputTypeText);
    inputTypeLine.getChildren().add(inputTypeFile);
    inputTypeText.setSelected(true);
    final TextField pathInput = new TextField();
    HBox.setHgrow(pathInput, Priority.ALWAYS);
    final Button selectLogFileButton = SelectFileButton.createButtonWithFileSelection(pathInput,
            LOG_FILE_ICON_NAME, "Select log file", null, null);
    final Text pathInputLabel = new Text("Log file path: ");
    final HBox fileInputConfig = new HBox();
    fileInputConfig.setAlignment(Pos.CENTER_LEFT);
    fileInputConfig.visibleProperty().bind(inputTypeFile.selectedProperty());
    fileInputConfig.managedProperty().bind(fileInputConfig.visibleProperty());
    fileInputConfig.getChildren().addAll(pathInputLabel, pathInput, selectLogFileButton);
    final TextArea logInputText = new TextArea();
    HBox.setHgrow(logInputText, Priority.ALWAYS);
    logInputText.setPrefRowCount(10);
    logInputText.setStyle("-fx-font-family: monospace");
    final HBox enterTextConfig = new HBox();
    enterTextConfig.getChildren().add(logInputText);
    enterTextConfig.visibleProperty().bind(inputTypeText.selectedProperty());
    enterTextConfig.managedProperty().bind(enterTextConfig.visibleProperty());
    final Button startBtn = new Button("Read Log");
    startBtn.setPadding(new Insets(8d));
    // CHECKSTYLE:ON
    startBtn.setGraphic(Icons.getIconGraphics("control_play_blue"));
    HBox.setHgrow(startBtn, Priority.ALWAYS);
    startBtn.setMaxWidth(Double.MAX_VALUE);
    startBtn.setOnAction(event -> this.runLogFileReader(inputTypeFile, pathInput, logInputText));
    final HBox startLine = new HBox();
    startLine.getChildren().add(startBtn);
    lines.getChildren().addAll(inputTypeLine, fileInputConfig, enterTextConfig, startLine, new Text("Results:"),
            this.parsedLogEntries);
    return lines;
}

From source file:fruitproject.FruitProject.java

public void first(final Stage primaryStage) {
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);//  ww  w.  j a  v a 2 s  .  c o m
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));

    rows = 0;
    addPairs.clear();

    Text lb = new Text();
    lb.setText("J-Fruit");
    //lb.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
    grid.add(lb, 1, 0);

    final ToggleGroup grp = new ToggleGroup();
    RadioButton rb1 = new RadioButton();
    rb1.setText("Add Fruit file");
    rb1.setUserData("add");
    rb1.setToggleGroup(grp);
    rb1.setSelected(true);
    grid.add(rb1, 1, 1);

    RadioButton rb2 = new RadioButton();
    rb2.setText("Load Fruit file");
    rb2.setUserData("load");
    rb2.setToggleGroup(grp);
    grid.add(rb2, 1, 2);

    Label label1 = new Label("Enter File Name:");
    final TextField tfFilename = new TextField();
    final HBox hb = new HBox();
    hb.getChildren().addAll(label1, tfFilename);
    hb.setSpacing(10);
    hb.setVisible(false);
    tfFilename.setText("");
    grid.add(hb, 1, 3);

    grp.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
        public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) {
            if (grp.getSelectedToggle() != null) {
                // System.out.println(grp.getSelectedToggle().getUserData().toString());
                if (grp.getSelectedToggle().getUserData().toString() == "load")
                    hb.setVisible(true);
                else {
                    hb.setVisible(false);
                    tfFilename.setText("");
                }
            }
        }
    });

    if (rb2.isSelected() == true) {
        hb.setVisible(true);
    }

    Button btn = new Button();
    btn.setText("GO");
    grid.add(btn, 1, 4);
    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            //System.out.println("Hello World!");
            if (tfFilename.getText() == "")
                second("");
            else
                second(tfFilename.getText());
            primaryStage.close();
        }
    });

    //StackPane root = new StackPane();
    //root.getChildren().add(lb);
    //root.getChildren().add(rb1);
    //root.getChildren().add(rb2);
    //root.getChildren().add(btn);

    Scene scene = new Scene(grid, 400, 450);
    primaryStage.setTitle("Hello World!");
    primaryStage.setScene(scene);
    primaryStage.show();

}

From source file:de.pixida.logtest.designer.testrun.TestRunEditor.java

public void createLogFileSourceInputItems(final List<Triple<String, Node, String>> formItems) {
    final TextField logFilePath = new TextField();
    this.logFilePathProperty.bind(logFilePath.textProperty());
    HBox.setHgrow(logFilePath, Priority.ALWAYS);
    final Button selectLogFileButton = SelectFileButton.createButtonWithFileSelection(logFilePath,
            LogReaderEditor.LOG_FILE_ICON_NAME, "Select log file", null, null);
    final HBox fileInputConfig = new HBox(logFilePath, selectLogFileButton);
    final VBox lines = new VBox();
    final double spacingOfLines = 5d;
    lines.setSpacing(spacingOfLines);/* w  w  w  .j a va2 s. co  m*/
    final HBox inputTypeLine = new HBox();
    final double hSpacingOfInputTypeChoices = 30d;
    inputTypeLine.setSpacing(hSpacingOfInputTypeChoices);
    final ToggleGroup group = new ToggleGroup();
    final RadioButton inputTypeText = new RadioButton("Paste/Enter log");
    inputTypeText.setToggleGroup(group);
    this.loadLogFromEnteredTextProperty.bind(inputTypeText.selectedProperty());
    final RadioButton inputTypeFile = new RadioButton("Read log file");
    inputTypeFile.setToggleGroup(group);
    this.loadLogFromFileProperty.bind(inputTypeFile.selectedProperty());
    inputTypeFile.setSelected(true);
    inputTypeLine.getChildren().add(inputTypeText);
    inputTypeLine.getChildren().add(inputTypeFile);
    fileInputConfig.visibleProperty().bind(inputTypeFile.selectedProperty());
    fileInputConfig.managedProperty().bind(fileInputConfig.visibleProperty());
    final TextArea logInputText = new TextArea();
    HBox.setHgrow(logInputText, Priority.ALWAYS);
    final int numLinesForEnteringLogInputManually = 10;
    logInputText.setPrefRowCount(numLinesForEnteringLogInputManually);
    logInputText.setStyle("-fx-font-family: monospace");
    this.enteredLogTextProperty.bind(logInputText.textProperty());
    final HBox enterTextConfig = new HBox();
    enterTextConfig.getChildren().add(logInputText);
    enterTextConfig.visibleProperty().bind(inputTypeText.selectedProperty());
    enterTextConfig.managedProperty().bind(enterTextConfig.visibleProperty());
    lines.getChildren().addAll(inputTypeLine, fileInputConfig, enterTextConfig);
    formItems.add(Triple.of("Trace Log", lines, null));
}

From source file:boundary.GraphPane.java

private HBox addTransformingModeOptions() {
    HBox hBox = new HBox();

    hBox.setPadding(new Insets(15, 12, 15, 12));
    hBox.setSpacing(10);//from  w w w  .ja v  a 2  s.  c  om
    hBox.setStyle("-fx-background-color: #66FFFF;");

    final ToggleGroup optionGroup = new ToggleGroup();

    Label lblMouseMode = new Label("Mouse Mode: ");
    lblMouseMode.setPrefSize(100, 20);

    RadioButton rbTransform = new RadioButton("Pan & Zoom");
    rbTransform.setPrefSize(100, 20);
    rbTransform.setToggleGroup(optionGroup);
    rbTransform.setUserData("T");
    rbTransform.setSelected(true);

    RadioButton rbPick = new RadioButton("Picking");
    rbPick.setPrefSize(100, 20);
    rbPick.setUserData("P");
    rbPick.setToggleGroup(optionGroup);

    optionGroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {

        @Override
        public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle newValue) {
            if (optionGroup.getSelectedToggle() != null) {
                DefaultModalGraphMouse dmg = (DefaultModalGraphMouse) vv.getGraphMouse();

                if (optionGroup.getSelectedToggle().getUserData().equals("T")) {
                    dmg.setMode(Mode.TRANSFORMING);
                } else if (optionGroup.getSelectedToggle().getUserData().equals("P")) {
                    dmg.setMode(Mode.PICKING);
                }
            }

        }
    });

    hBox.getChildren().addAll(lblMouseMode, rbTransform, rbPick);

    return hBox;

}

From source file:de.pixida.logtest.designer.automaton.AutomatonEdge.java

private Node createRadioButtonInput(final ToggleGroup tg, final String propertyName,
        final boolean isInitiallySelected, final Consumer<Boolean> applyValue) {
    final RadioButton result = new RadioButton(propertyName);
    result.setToggleGroup(tg);
    result.setSelected(isInitiallySelected);
    result.setOnAction(event -> {//from   ww  w .  j ava  2 s . c om
        applyValue.accept(result.isSelected());
        this.getGraph().handleChange();
    });
    return result;
}