Example usage for javafx.scene.control ChoiceBox setValue

List of usage examples for javafx.scene.control ChoiceBox setValue

Introduction

In this page you can find the example usage for javafx.scene.control ChoiceBox setValue.

Prototype

public final void setValue(T value) 

Source Link

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    ChoiceBox<String> choiceBox = new ChoiceBox<String>();
    choiceBox.setItems(cursors);//from w w w .ja  v  a2 s .c  om

    choiceBox.setValue("a");

    VBox box = new VBox();
    box.getChildren().add(choiceBox);
    final Scene scene = new Scene(box, 300, 250);
    scene.setFill(null);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setScene(scene);//from  w w w. j  av a 2 s .c  o  m
    stage.show();

    stage.setWidth(300);
    stage.setHeight(200);

    final String[] greetings = new String[] { "Hello", "Hola", "1", "2" };
    final ChoiceBox cb = new ChoiceBox(FXCollections.observableArrayList("1", "2", "3", "4"));
    cb.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
        public void changed(ObservableValue ov, Number value, Number new_value) {
            System.out.println(new_value.intValue());
        }
    });

    cb.setValue("2");
    HBox hb = new HBox();
    hb.getChildren().addAll(cb);
    hb.setSpacing(30);
    hb.setAlignment(Pos.CENTER);
    hb.setPadding(new Insets(10, 0, 0, 10));

    ((Group) scene.getRoot()).getChildren().add(hb);

}

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

private void createConfigFrame() {
    final int descriptionInputLines = 8;
    this.descriptionInput.setPrefRowCount(descriptionInputLines);
    this.descriptionInput.setWrapText(true);
    this.descriptionInput.textProperty()
            .addListener((ChangeListener<String>) (observable, oldValue, newValue) -> {
                this.setDescription(newValue);
                this.graph.handleChange();
            });//from ww w. j  a  va 2s.  co m
    this.configFrame.addOption("Description", this.descriptionInput);

    final ObservableList<String> options = FXCollections.observableArrayList("JavaScript", "python");
    if (!options.contains(Automaton.DEFAULT_SCRIPTING_LANGUAGE)) {
        options.add(0, Automaton.DEFAULT_SCRIPTING_LANGUAGE);
    }
    final ChoiceBox<String> scriptLanguageInput = new ChoiceBox<>(options);
    scriptLanguageInput
            .setValue(StringUtils.isBlank(this.scriptLanguage) || !options.contains(this.scriptLanguage)
                    ? Automaton.DEFAULT_SCRIPTING_LANGUAGE
                    : this.scriptLanguage);
    scriptLanguageInput.getSelectionModel().selectedIndexProperty()
            .addListener((ChangeListener<Number>) (observable, oldValue, newValue) -> {
                EditorAutomaton.this.scriptLanguage = scriptLanguageInput.getItems().get((Integer) newValue);
                this.graph.handleChange();
            });
    this.configFrame.addOption("Script language", scriptLanguageInput);

    final int onLoadInputLines = 8;
    this.onLoadInput.setPrefRowCount(onLoadInputLines);
    this.onLoadInput.setWrapText(true);
    this.onLoadInput.setStyle("-fx-font-family: monospace");
    this.onLoadInput.textProperty().addListener((ChangeListener<String>) (observable, oldValue, newValue) -> {
        this.graph.handleChange();
    });
    this.configFrame.addOption("On Load", this.onLoadInput);
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    scene.setFill(Color.ALICEBLUE);
    stage.setScene(scene);/*from   ww  w . ja v  a 2s. com*/
    stage.show();

    stage.setWidth(300);
    stage.setHeight(200);

    label.setStyle("-fx-font: 25 arial;");
    label.setLayoutX(40);

    rect.setStroke(Color.BLUE);
    rect.setStrokeWidth(3);
    rect.setFill(Color.WHITE);

    final String[] greetings = new String[] { "A", "B", "C", "D", "E" };
    final ChoiceBox<String> cb = new ChoiceBox<String>(
            FXCollections.observableArrayList("a", "b", "c", "d", "e"));

    cb.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
        public void changed(ObservableValue ov, Number value, Number new_value) {
            label.setText(greetings[new_value.intValue()]);
        }
    });

    cb.setTooltip(new Tooltip("Select the language"));
    cb.setValue("English");
    HBox hb = new HBox();
    hb.getChildren().addAll(cb, label);
    hb.setSpacing(30);
    hb.setAlignment(Pos.CENTER);
    hb.setPadding(new Insets(10, 0, 0, 10));

    ((Group) scene.getRoot()).getChildren().add(hb);

}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    scene.setFill(Color.ALICEBLUE);
    stage.setScene(scene);// w  w  w .  j av  a2  s  .c  om
    stage.show();

    stage.setTitle("ChoiceBox Sample");
    stage.setWidth(300);
    stage.setHeight(200);

    label.setStyle("-fx-font: 25 arial;");
    label.setLayoutX(40);

    rect.setArcHeight(8);
    rect.setArcWidth(8);
    rect.setStroke(Color.BLUE);
    rect.setStrokeWidth(3);
    rect.setFill(Color.WHITE);

    final String[] greetings = new String[] { "Hello", "Hola", "??????", "?", "?????" };
    final ChoiceBox cb = new ChoiceBox(
            FXCollections.observableArrayList("English", "Espaol", "???????", "????", "???"));

    cb.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
        public void changed(ObservableValue ov, Number value, Number new_value) {
            label.setText(greetings[new_value.intValue()]);
        }
    });

    cb.setTooltip(new Tooltip("Select the language"));
    cb.setValue("English");
    HBox hb = new HBox();
    hb.getChildren().addAll(cb, label);
    hb.setSpacing(30);
    hb.setAlignment(Pos.CENTER);
    hb.setPadding(new Insets(10, 0, 0, 10));

    ((Group) scene.getRoot()).getChildren().add(hb);

}

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

private void createDurationInput(final GridPane gp, final boolean isMin,
        final TimeIntervalForEditing timeInterval) {
    final DurationForEditing duration = isMin ? timeInterval.getMinDuration() : timeInterval.getMaxDuration();

    final int targetRow = isMin ? 0 : 1;
    int column = 0;

    final Text fromOrTo = new Text((isMin ? "Min" : "Max") + ": ");
    gp.add(fromOrTo, column++, targetRow);

    final String mathOperator = isMin ? ">" : "<";
    final String inclusive = "Inclusive: " + mathOperator + "=";
    final String exclusive = "Exclusive: " + mathOperator;
    final ChoiceBox<String> intervalBorderInput = new ChoiceBox<>(
            FXCollections.observableArrayList(inclusive, exclusive));
    intervalBorderInput.setValue(duration.isInclusive() ? inclusive : exclusive);
    intervalBorderInput.getSelectionModel().selectedIndexProperty()
            .addListener((ChangeListener<Number>) (observable, oldValue, newValue) -> {
                duration.setInclusive(0 == (Integer) newValue);
                this.timingConditionsUpdated();
                this.getGraph().handleChange();
            });/*from www  .j  a  va2s  .  com*/
    gp.add(intervalBorderInput, column++, targetRow);

    final TextField valueInput = new TextField(duration.getValue());
    valueInput.textProperty().addListener((ChangeListener<String>) (observable, oldValue, newValue) -> {
        duration.setValue(newValue);
        this.timingConditionsUpdated();
        this.getGraph().handleChange();
    });
    gp.add(valueInput, column++, targetRow);

    final String currentChoice = JsonTimeUnit.convertTimeUnitToString(duration.getUnit());
    final ChoiceBox<String> timeUnitInput = new ChoiceBox<>(
            FXCollections.observableArrayList(JsonTimeUnit.getListOfPossibleNames()));
    timeUnitInput.setValue(currentChoice);
    timeUnitInput.getSelectionModel().selectedIndexProperty()
            .addListener((ChangeListener<Number>) (observable, oldValue, newValue) -> {
                duration.setUnit(JsonTimeUnit.indexToTimeUnit((Integer) newValue));
                this.timingConditionsUpdated();
                this.getGraph().handleChange();
            });
    gp.add(timeUnitInput, column++, targetRow);
}