Java Code Examples for javafx.scene.control.ChoiceBox#setConverter()
The following examples show how to use
javafx.scene.control.ChoiceBox#setConverter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChoiceBoxDemo.java From examples-javafx-repos1 with Apache License 2.0 | 5 votes |
@Override public void start(Stage primaryStage) throws Exception { VBox vbox = new VBox(); vbox.setPadding(new Insets(10)); vbox.setAlignment(Pos.CENTER); vbox.setSpacing(10); Label label = new Label("Make Yes/No Selection"); ChoiceBox<Pair<String, String>> cb = new ChoiceBox<>(); cb.setItems( Constants.LIST_YES_NO ); cb.setConverter( new PairStringConverter() ); cb.setValue( Constants.PAIR_NO ); Label labelOpt = new Label("Make Yes/No Selection (Optional)"); ChoiceBox<Pair<String, String>> cbOpt = new ChoiceBox<>(); cbOpt.setItems( Constants.LIST_YES_NO_OPT ); cbOpt.setConverter(new PairStringConverter(true) ); cbOpt.setValue( Constants.PAIR_NULL ); Button b = new Button("Save"); b.setOnAction( (evt) -> System.out.println("Selections - yes/no was '" + cb.getValue() + "' and yes/no/opt was '" + cbOpt.getValue() + "'") ); vbox.getChildren().addAll(label, cb, labelOpt, cbOpt, b); Scene scene = new Scene(vbox); primaryStage.setTitle("Choice Box Demo"); primaryStage.setHeight(200); primaryStage.setWidth(300); primaryStage.setScene( scene ); primaryStage.show(); }
Example 2
Source File: ConfigurationUIController.java From jace with GNU General Public License v2.0 | 5 votes |
private Node buildDynamicSelectComponent(ConfigNode node, String settingName, Serializable value) { try { DynamicSelection sel = (DynamicSelection) node.subject.getClass().getField(settingName).get(node.subject); ChoiceBox widget = new ChoiceBox(FXCollections.observableList(new ArrayList(sel.getSelections().keySet()))); widget.setMinWidth(175.0); widget.setConverter(new StringConverter() { @Override public String toString(Object object) { return (String) sel.getSelections().get(object); } @Override public Object fromString(String string) { return sel.findValueByMatch(string); } }); Object selected = value == null ? null : widget.getConverter().fromString(String.valueOf(value)); if (selected == null) { widget.getSelectionModel().selectFirst(); } else { widget.setValue(selected); } widget.valueProperty().addListener((Observable e) -> { node.setFieldValue(settingName, widget.getConverter().toString(widget.getValue())); }); return widget; } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) { Logger.getLogger(ConfigurationUIController.class.getName()).log(Level.SEVERE, null, ex); return null; } }
Example 3
Source File: TopsoilPlotEvolution.java From ET_Redux with Apache License 2.0 | 4 votes |
@Override public List<Node> toolbarControlsFactory() { List<Node> controls = super.toolbarControlsFactory(); CheckBox ellipsesCheckBox = new CheckBox("Ellipses"); ellipsesCheckBox.setSelected(true); ellipsesCheckBox.setOnAction(mouseEvent -> { plot.setProperty(ELLIPSES, ellipsesCheckBox.isSelected()); }); ChoiceBox<SigmaPresentationModes> uncertaintyChoiceBox = new ChoiceBox<>(FXCollections.observableArrayList(SigmaPresentationModes.values())); uncertaintyChoiceBox.setValue(SigmaPresentationModes.TWO_SIGMA_ABSOLUTE); uncertaintyChoiceBox.setConverter(new StringConverter<SigmaPresentationModes>() { @Override public String toString(SigmaPresentationModes object) { return object.getDisplayName(); } @Override public SigmaPresentationModes fromString(String string) { return null; } }); uncertaintyChoiceBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<SigmaPresentationModes>() { @Override public void changed(ObservableValue observable, SigmaPresentationModes oldValue, SigmaPresentationModes newValue) { plot.setProperty(UNCERTAINTY, newValue.getSigmaMultiplier()); } }); ColorPicker ellipsesColorPicker = new ColorPicker(Color.RED); ellipsesColorPicker.setStyle("-fx-font-size: 8px; -fx-font-family: 'Courier New';"); ellipsesColorPicker.setPrefWidth(100); ellipsesColorPicker.setOnAction(mouseEvent -> { // to satisfy D3 plot.setProperty(ELLIPSE_FILL_COLOR, ellipsesColorPicker.getValue().toString().substring(0, 8).replaceAll("0x", "#")); }); CheckBox matrixCheckBox = new CheckBox("Matrix"); matrixCheckBox.setSelected(true); matrixCheckBox.setOnAction(mouseEvent -> { plot.setProperty(EVOLUTION_MATRIX, matrixCheckBox.isSelected()); }); CheckBox allSelectedCheckBox = new CheckBox("Select All"); allSelectedCheckBox.setSelected(true); allSelectedCheckBox.setOnAction(mouseEvent -> { setSelectedAllData(allSelectedCheckBox.isSelected()); }); CheckBox regressionUnctEnvelopeCheckBox = new CheckBox("2D Regression Unct"); regressionUnctEnvelopeCheckBox.setSelected(false); regressionUnctEnvelopeCheckBox.setOnAction(mouseEvent -> { plot.setProperty(REGRESSION_ENVELOPE, regressionUnctEnvelopeCheckBox.isSelected()); }); CheckBox regressionCheckBox = new CheckBox("2D Regression"); regressionCheckBox.setSelected(false); regressionUnctEnvelopeCheckBox.setDisable(true); regressionCheckBox.setOnAction(mouseEvent -> { boolean isRegression = regressionCheckBox.isSelected(); plot.setProperty(REGRESSION_LINE, isRegression); regressionUnctEnvelopeCheckBox.setDisable(!isRegression); }); controls.add(ellipsesCheckBox); controls.add(uncertaintyChoiceBox); controls.add(ellipsesColorPicker); controls.add(allSelectedCheckBox); controls.add(matrixCheckBox); controls.add(regressionCheckBox); controls.add(regressionUnctEnvelopeCheckBox); return controls; }
Example 4
Source File: TopsoilPlotWetherill.java From ET_Redux with Apache License 2.0 | 4 votes |
@Override public List<Node> toolbarControlsFactory() { List<Node> controls = super.toolbarControlsFactory(); CheckBox ellipsesCheckBox = new CheckBox("Ellipses"); ellipsesCheckBox.setSelected(true); ellipsesCheckBox.setOnAction(mouseEvent -> { plot.setProperty(ELLIPSES, ellipsesCheckBox.isSelected()); }); ChoiceBox<SigmaPresentationModes> uncertaintyChoiceBox = new ChoiceBox<>(FXCollections.observableArrayList(SigmaPresentationModes.values())); uncertaintyChoiceBox.setValue(SigmaPresentationModes.TWO_SIGMA_ABSOLUTE); uncertaintyChoiceBox.setConverter(new StringConverter<SigmaPresentationModes>() { @Override public String toString(SigmaPresentationModes object) { return object.getDisplayName(); } @Override public SigmaPresentationModes fromString(String string) { return null; } }); uncertaintyChoiceBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<SigmaPresentationModes>() { @Override public void changed(ObservableValue observable, SigmaPresentationModes oldValue, SigmaPresentationModes newValue) { plot.setProperty(UNCERTAINTY, newValue.getSigmaMultiplier()); } }); ColorPicker ellipsesColorPicker = new ColorPicker(Color.RED); ellipsesColorPicker.setStyle("-fx-font-size: 8px; -fx-font-family: 'Courier New';"); ellipsesColorPicker.setPrefWidth(100); ellipsesColorPicker.setOnAction(mouseEvent -> { // to satisfy D3 plot.setProperty(ELLIPSE_FILL_COLOR, ellipsesColorPicker.getValue().toString().substring(0, 8).replaceAll("0x", "#")); }); CheckBox concordiaLineCheckBox = new CheckBox("Concordia"); concordiaLineCheckBox.setSelected(true); concordiaLineCheckBox.setOnAction(mouseEvent -> { plot.setProperty(CONCORDIA_LINE, concordiaLineCheckBox.isSelected()); }); CheckBox allSelectedCheckBox = new CheckBox("Select All"); allSelectedCheckBox.setSelected(true); allSelectedCheckBox.setOnAction(mouseEvent -> { setSelectedAllData(allSelectedCheckBox.isSelected()); }); CheckBox regressionUnctEnvelopeCheckBox = new CheckBox("2D Regression Unct"); regressionUnctEnvelopeCheckBox.setSelected(false); regressionUnctEnvelopeCheckBox.setOnAction(mouseEvent -> { plot.setProperty(REGRESSION_ENVELOPE, regressionUnctEnvelopeCheckBox.isSelected()); }); CheckBox regressionCheckBox = new CheckBox("2D Regression"); regressionCheckBox.setSelected(false); regressionUnctEnvelopeCheckBox.setDisable(true); regressionCheckBox.setOnAction(mouseEvent -> { boolean isRegression = regressionCheckBox.isSelected(); plot.setProperty(REGRESSION_LINE, isRegression); regressionUnctEnvelopeCheckBox.setDisable(!isRegression); }); controls.add(ellipsesCheckBox); controls.add(uncertaintyChoiceBox); controls.add(ellipsesColorPicker); controls.add(allSelectedCheckBox); controls.add(concordiaLineCheckBox); controls.add(regressionCheckBox); controls.add(regressionUnctEnvelopeCheckBox); return controls; }