List of usage examples for javafx.scene.control ChoiceBox setConverter
public final void setConverter(StringConverter<T> value)
From source file:Main.java
@Override public void start(Stage stage) { ChoiceBox<String> choiceBox = new ChoiceBox<String>(cursors); StringConverter sc = new NumberStringConverter(); choiceBox.setConverter(sc); VBox box = new VBox(); box.getChildren().add(choiceBox);//from w w w .j a va 2s.c o m final Scene scene = new Scene(box, 300, 250); scene.setFill(null); stage.setScene(scene); stage.show(); }
From source file:de.pixida.logtest.designer.logreader.LogReaderEditor.java
public void createInputForHandlingOfNonHeadlineLines(final List<Triple<String, Node, String>> formItems) { final Map<HandlingOfNonHeadlineLines, String> mapValueToChoice = new HashMap<>(); mapValueToChoice.put(HandlingOfNonHeadlineLines.FAIL, "Abort - Each line in the log file is assumed to be a log entry"); mapValueToChoice.put(HandlingOfNonHeadlineLines.CREATE_MULTILINE_ENTRY, "Append to payload - This will create multiline payloads"); mapValueToChoice.put(HandlingOfNonHeadlineLines.ASSUME_LAST_TIMESTAMP, "Create new log entry and use timestamp of recent log entry"); mapValueToChoice.put(HandlingOfNonHeadlineLines.ASSUME_LAST_TIMESTAMP_AND_CHANNEL, "Create new log entry and use timestamp and channel of recent log entry"); final ChoiceBox<HandlingOfNonHeadlineLines> handlingOfNonHeadlineLinesInput = new ChoiceBox<>( FXCollections.observableArrayList(HandlingOfNonHeadlineLines.values())); handlingOfNonHeadlineLinesInput.setConverter(new StringConverter<HandlingOfNonHeadlineLines>() { @Override/*w ww. ja va 2 s . co m*/ public String toString(final HandlingOfNonHeadlineLines object) { return mapValueToChoice.get(object); } @Override public HandlingOfNonHeadlineLines fromString(final String string) { for (final Entry<HandlingOfNonHeadlineLines, String> entry : mapValueToChoice.entrySet()) { if (entry.getValue() == string) // Intentionally comparing references to obtain a bijection { return entry.getKey(); } } return null; // Should never happen } }); handlingOfNonHeadlineLinesInput.getSelectionModel().select(this.logReader.getHandlingOfNonHeadlineLines()); handlingOfNonHeadlineLinesInput.getSelectionModel().selectedIndexProperty() .addListener((ChangeListener<Number>) (observable, oldValue, newValue) -> { this.logReader.setHandlingOfNonHeadlineLines( handlingOfNonHeadlineLinesInput.getItems().get(newValue.intValue())); this.setChanged(true); }); formItems.add(Triple.of("Dangling Lines", handlingOfNonHeadlineLinesInput, "Define what to do if dangling lines are spotted. Dangling lines are lines which do not match the headline pattern, i.e." + " which do not introduce a new log entry.")); }
From source file:net.sourceforge.pmd.util.fxdesigner.XPathPanelController.java
public void initialiseVersionChoiceBox(ChoiceBox<String> choiceBox) { this.xpathVersionChoiceBox = choiceBox; ObservableList<String> versionItems = choiceBox.getItems(); versionItems.add(XPathRuleQuery.XPATH_1_0); versionItems.add(XPathRuleQuery.XPATH_1_0_COMPATIBILITY); versionItems.add(XPathRuleQuery.XPATH_2_0); xpathVersionChoiceBox.getSelectionModel().select(XPathRuleQuery.XPATH_2_0); choiceBox.setConverter(DesignerUtil.stringConverter(s -> "XPath " + s, s -> s.substring(6))); }