List of usage examples for javafx.scene.control ChoiceBox getSelectionModel
public final SingleSelectionModel<T> getSelectionModel()
From source file:Main.java
private static Node createLoginPanel() { final ToggleGroup toggleGroup = new ToggleGroup(); final TextField textField = new TextField(); textField.setPrefColumnCount(10);// ww w.j a va2 s .co m textField.setPromptText("Your name"); final PasswordField passwordField = new PasswordField(); passwordField.setPrefColumnCount(10); passwordField.setPromptText("Your password"); final ChoiceBox<String> choiceBox = new ChoiceBox<String>(FXCollections.observableArrayList("English", "\u0420\u0443\u0441\u0441\u043a\u0438\u0439", "Fran\u00E7ais")); choiceBox.setTooltip(new Tooltip("Your language")); choiceBox.getSelectionModel().select(0); final HBox panel = createHBox(6, createVBox(2, createRadioButton("High", toggleGroup, true), createRadioButton("Medium", toggleGroup, false), createRadioButton("Low", toggleGroup, false)), createVBox(2, textField, passwordField), choiceBox); panel.setAlignment(Pos.BOTTOM_LEFT); configureBorder(panel); return panel; }
From source file:Main.java
@Override public void start(Stage stage) { ChoiceBox choiceBox = new ChoiceBox(cursors); System.out.println(choiceBox.getSelectionModel()); VBox box = new VBox(); box.getChildren().add(choiceBox);/*from www. ja va 2 s.c o m*/ 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);// w w w. j av a 2s . 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:Main.java
@Override public void start(Stage stage) { ChoiceBox<String> choiceBox = new ChoiceBox<String>(); choiceBox.setItems(cursors);//from www . j av a2s .co m SingleSelectionModel ssm = choiceBox.getSelectionModel(); choiceBox.setSelectionModel(ssm); 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()); scene.setFill(Color.ALICEBLUE); stage.setScene(scene);// www .ja v a 2 s .co m 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 ww . j av a2s. com*/ 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:Main.java
@Override public void start(Stage stage) { ChoiceBox choiceBoxRef = ChoiceBoxBuilder.create().items(cursors).build(); VBox box = new VBox(); box.getChildren().add(choiceBoxRef); final Scene scene = new Scene(box, 300, 250); scene.setFill(null);/* w w w.j av a2 s . c o m*/ stage.setScene(scene); stage.show(); scene.cursorProperty().bind(choiceBoxRef.getSelectionModel().selectedItemProperty()); }
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(); });// w w w.j a va 2 s. c o 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:de.pixida.logtest.designer.logreader.LogReaderEditor.java
private List<Triple<String, Node, String>> createConfigurationForm() { final List<Triple<String, Node, String>> formItems = new ArrayList<>(); // Headline pattern final TextField textInput = new TextField(this.logReader.getHeadlinePattern()); textInput.textProperty().addListener((ChangeListener<String>) (observable, oldValue, newValue) -> { this.logReader.setHeadlinePattern(newValue); this.setChanged(true); });/*from w w w. j av a2 s .co m*/ textInput.setStyle("-fx-font-family: monospace"); formItems.add(Triple.of("Headline Pattern", textInput, "The perl style regular expression is used to spot the beginning of" + " log entries in the log file. If a log entry consists of multiple lines, this pattern must only match the first" + " line, called \"head line\". Groups can intentionally be matched to spot values like timestamp or channel name." + " All matching groups are removed from the payload before they are processed by an automaton.")); // Index of timestamp Supplier<Integer> getter = () -> this.logReader.getHeadlinePatternIndexOfTimestamp(); Consumer<Integer> setter = value -> this.logReader.setHeadlinePatternIndexOfTimestamp(value); final TextField indexOfTimestampInput = this.createIntegerInputField(textInput, getter, setter); formItems.add(Triple.of("Timestamp Group", indexOfTimestampInput, "Denotes which matching group in the headline pattern contains" + " the timestamp. Index 0 references the whole pattern match, index 1 is the first matching group etc. The timestamp must" + " always be a valid integer. Currently, this integer is always interpreted as milliseconds. If no value is set, no" + " timestamp will be extracted and timing conditions cannot be used. If the referenced matching group is optional" + " and does not match for a specific head line, the last recent timestamp will be used for the extracted log entry.")); // Index of channel getter = () -> this.logReader.getHeadlinePatternIndexOfChannel(); setter = value -> this.logReader.setHeadlinePatternIndexOfChannel(value); final TextField indexOfChannelInput = this.createIntegerInputField(textInput, getter, setter); formItems.add(Triple.of("Channel Group", indexOfChannelInput, "Denotes which matching group in the headline pattern contains" + " the channel. If the value is empty or the matching group is optional and it did not match, the default channel is used" + " for the extracted log entry.")); // Trim payload CheckBox cb = new CheckBox(); cb.setSelected(this.logReader.getTrimPayload()); cb.selectedProperty().addListener((ChangeListener<Boolean>) (observable, oldValue, newValue) -> { this.logReader.setTrimPayload(BooleanUtils.toBoolean(newValue)); this.setChanged(true); }); formItems.add(Triple.of("Trim Payload", cb, "Only has effect on multiline payloads." + " If enabled, all leading and trailing whitespaces are removed from the payload" + " after the matching groups are removed. This allows for regular expressions in the automaton that match the beginning" + " and the end of the payload, without having to take care too much for whitespaces in the source log file.")); // Handling of non headline lines this.createInputForHandlingOfNonHeadlineLines(formItems); // Trim payload cb = new CheckBox(); cb.setSelected(this.logReader.getRemoveEmptyPayloadLinesFromMultilineEntry()); cb.selectedProperty().addListener((ChangeListener<Boolean>) (observable, oldValue, newValue) -> { this.logReader.setRemoveEmptyPayloadLinesFromMultilineEntry(BooleanUtils.toBoolean(newValue)); this.setChanged(true); }); formItems.add(Triple.of("Remove Empty Lines", cb, "If enabled, empty lines will be removed from multiline payload entries.")); // Charset final SortedMap<String, Charset> charsets = Charset.availableCharsets(); final ChoiceBox<String> encodingInput = new ChoiceBox<>( FXCollections.observableArrayList(charsets.keySet())); encodingInput.getSelectionModel().select(this.logReader.getLogFileCharset().name()); encodingInput.getSelectionModel().selectedItemProperty() .addListener((ChangeListener<String>) (observable, oldValue, newValue) -> { this.logReader.setLogFileCharset(charsets.get(newValue)); this.setChanged(true); }); formItems.add(Triple.of("Log File Encoding", encodingInput, "Encoding of the log file. Note that some of the encodings are" + " platform specific such that reading the log on a different platform might fail. Usually, log files are written" + " using UTF-8, UTF-16, ISO-8859-1 or ASCII.")); return formItems; }
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(); });/* www . ja v a 2 s . 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); }