/** * init fxml when loaded. */ @PostConstruct public void init() { jfxComboBox.focusedProperty().addListener((o, oldVal, newVal) -> { if (!newVal) { jfxComboBox.validate(); } }); ChangeListener<? super Boolean> comboBoxFocus = (o, oldVal, newVal) -> { if (!newVal) { jfxEditableComboBox.validate(); } }; jfxEditableComboBox.focusedProperty().addListener(comboBoxFocus); jfxEditableComboBox.getEditor().focusedProperty().addListener(comboBoxFocus); jfxEditableComboBox.setConverter(new StringConverter<Label>() { @Override public String toString(Label object) { return object==null? "" : object.getText(); } @Override public Label fromString(String string) { return string == null || string.isEmpty() ? null : new Label(string); } }); }
@Override public StyleableBooleanProperty getStyleableProperty(JFXComboBox control) { return control.disableAnimationProperty(); } };
@Override public StyleableProperty<Paint> getStyleableProperty(JFXComboBox<?> control) { return control.focusColorProperty(); } };
@Override public void start(Stage primaryStage) throws Exception { JFXComboBox<Label> combo = new JFXComboBox<>(); combo.getItems().add(new Label("Java 1.8")); combo.getItems().add(new Label("Java 1.7")); combo.getItems().add(new Label("Java 1.6")); combo.getItems().add(new Label("Java 1.5")); combo.setEditable(true); combo.setPromptText("Select Java Version"); combo.setConverter(new StringConverter<Label>() { @Override public String toString(Label object) { return object==null? "" : object.getText(); } @Override public Label fromString(String string) { return new Label(string); } }); HBox pane = new HBox(100); HBox.setMargin(combo, new Insets(20)); pane.setStyle("-fx-background-color:WHITE"); pane.getChildren().add(combo); final Scene scene = new Scene(pane, 300, 300); scene.getStylesheets().add(ComboBoxDemo.class.getResource("/css/jfoenix-components.css").toExternalForm()); primaryStage.setTitle("JFX ComboBox Demo"); primaryStage.setScene(scene); primaryStage.setResizable(false); primaryStage.show(); }
comboBox, promptTextFill, comboBox.valueProperty(), comboBox.promptTextProperty(), () -> promptText); if (comboBox.isEditable()) { comboBox.getEditor().setStyle("-fx-background-color:TRANSPARENT;-fx-padding: 0.333333em 0em;"); comboBox.getEditor().promptTextProperty().unbind(); comboBox.getEditor().setPromptText(null); comboBox.getEditor().textProperty().addListener((o, oldVal, newVal) -> { linesWrapper.usePromptText.invalidate(); comboBox.setValue(getConverter().fromString(newVal)); }); registerChangeListener(comboBox.disableProperty(), "DISABLE_NODE"); registerChangeListener(comboBox.focusColorProperty(), "FOCUS_COLOR"); registerChangeListener(comboBox.unFocusColorProperty(), "UNFOCUS_COLOR"); registerChangeListener(comboBox.disableAnimationProperty(), "DISABLE_ANIMATION");
private boolean updateDisplayText(ListCell<T> cell, T item, boolean empty) { if (empty) { // create empty cell if (cell == null) { return true; } cell.setGraphic(null); cell.setText(null); return true; } else if (item instanceof Node) { Node currentNode = cell.getGraphic(); Node newNode = (Node) item; // create a node from the selected node of the listview // using JFXComboBox {@link #nodeConverterProperty() NodeConverter}) NodeConverter<T> nc = this.getNodeConverter(); Node node = nc == null ? null : nc.toNode(item); if (currentNode == null || !currentNode.equals(newNode)) { cell.setText(null); cell.setGraphic(node == null ? newNode : node); } return node == null; } else { // run item through StringConverter if it isn't null StringConverter<T> c = this.getConverter(); String s = item == null ? this.getPromptText() : (c == null ? item.toString() : c.toString(item)); cell.setText(s); cell.setGraphic(null); return s == null || s.isEmpty(); } }
private void initCombos() { // USER COMBOBOX Collections.sort(this.selectUserCombo.getItems()); this.selectUserCombo.getSelectionModel().selectedItemProperty().addListener((v, oldValue, newValue) -> { if (newValue != null) { this.loadUserProfile(newValue); } }); }
@Override @SuppressWarnings("unchecked") public StyleableProperty<Paint> getStyleableProperty(JFXComboBox n) { final JFXComboBoxListViewSkin<?> skin = (JFXComboBoxListViewSkin<?>) n.getSkin(); return (StyleableProperty<Paint>) skin.promptTextFill; } };
@Override public List<CssMetaData<? extends Styleable, ?>> getControlCssMetaData() { if (STYLEABLES == null) { final List<CssMetaData<? extends Styleable, ?>> styleables = new ArrayList<>(Control.getClassCssMetaData()); styleables.addAll(ComboBox.getClassCssMetaData()); styleables.addAll(getClassCssMetaData()); STYLEABLES = Collections.unmodifiableList(styleables); } return STYLEABLES; }
@Override public void refreshUsers() { Platform.runLater(() -> { try { // clear all users this.selectUserCombo.getItems().clear(); // reload the users FileManager.getAllUserFolder().stream().forEachOrdered(t -> this.selectUserCombo.getItems().add(t)); } catch (final IOException e) { ViewUtilities.showNotificationPopup("Exception", "Cannot read user data", Duration.MEDIUM, NotificationType.WARNING, null); } }); }
comboBox, promptTextFill, comboBox.valueProperty(), comboBox.promptTextProperty(), () -> promptText); if (comboBox.isEditable()) { comboBox.getEditor().setStyle("-fx-background-color:TRANSPARENT;-fx-padding: 0.333333em 0em;"); comboBox.getEditor().promptTextProperty().unbind(); comboBox.getEditor().setPromptText(null); comboBox.getEditor().textProperty().addListener((o, oldVal, newVal) -> linesWrapper.usePromptText.invalidate()); registerChangeListener(comboBox.disableProperty(), obs -> linesWrapper.updateDisabled()); registerChangeListener(comboBox.focusColorProperty(), obs -> linesWrapper.updateFocusColor()); registerChangeListener(comboBox.unFocusColorProperty(), obs -> linesWrapper.updateUnfocusColor()); registerChangeListener(comboBox.disableAnimationProperty(), obs -> errorContainer.updateClip());
private boolean updateDisplayText(ListCell<T> cell, T item, boolean empty) { if (empty) { // create empty cell if (cell == null) { return true; } cell.setGraphic(null); cell.setText(null); return true; } else if (item instanceof Node) { Node currentNode = cell.getGraphic(); Node newNode = (Node) item; // create a node from the selected node of the listview // using JFXComboBox {@link #nodeConverterProperty() NodeConverter}) NodeConverter<T> nc = this.getNodeConverter(); Node node = nc == null ? null : nc.toNode(item); if (currentNode == null || !currentNode.equals(newNode)) { cell.setText(null); cell.setGraphic(node == null ? newNode : node); } return node == null; } else { // run item through StringConverter if it isn't null StringConverter<T> c = this.getConverter(); String s = item == null ? this.getPromptText() : (c == null ? item.toString() : c.toString(item)); cell.setText(s); cell.setGraphic(null); return s == null || s.isEmpty(); } }
private void initSliders() { for (final UpdateRate elem : UpdateRate.values()) { this.udpateRateCombo.getItems().add(elem); } this.udpateRateCombo.getSelectionModel().selectedItemProperty().addListener( (observable, oldValue, newValue) -> this.setUpdateRate(newValue)); this.sliderRadius.valueProperty().addListener( (observable, oldValue, newValue) -> this.setDtwRadius(newValue.doubleValue() / 10)); this.sliderMinThreshold.valueProperty().addListener( (observable, oldValue, newValue) -> this.setMinDtwThreashold(newValue.intValue())); this.sliderMaxThreshold.valueProperty().addListener( (observable, oldValue, newValue) -> this.setMaxDtwThreashold(newValue.intValue())); this.sliderTimeSeparation.valueProperty().addListener( (observable, oldValue, newValue) -> this.setMinTimeSeparation(newValue.intValue())); this.sliderMatchNumber.valueProperty().addListener( (observable, oldValue, newValue) -> this.setMatchNumber(newValue.intValue())); // CHECKSTYLE:OFF this.elevationSlider = new JFXSlider(0, 30, 10); this.elevationSlider.setMajorTickUnit(5); this.elevationSlider.setSnapToTicks(true); this.elevationSlider.setMinorTickCount(0); this.elevationSlider.setMinHeight(50); this.elevationSlider.valueProperty().addListener((oservable, oldValue, newValue) -> { new Thread(() -> { this.setSensorElevation(newValue.intValue()); }).start(); }); // CHECKSTYLE:ON }
@Override public boolean isSettable(JFXComboBox n) { final JFXComboBoxListViewSkin<?> skin = (JFXComboBoxListViewSkin<?>) n.getSkin(); return skin.promptTextFill == null || !skin.promptTextFill.isBound(); }
@Override public List<CssMetaData<? extends Styleable, ?>> getControlCssMetaData() { if (STYLEABLES == null) { final List<CssMetaData<? extends Styleable, ?>> styleables = new ArrayList<>(Control.getClassCssMetaData()); styleables.addAll(ComboBox.getClassCssMetaData()); styleables.addAll(getClassCssMetaData()); STYLEABLES = Collections.unmodifiableList(styleables); } return STYLEABLES; }
@Override public final Boolean isDisableAnimation() { return disableAnimation != null && this.disableAnimationProperty().get(); }
@Override @SuppressWarnings("unchecked") public StyleableProperty<Paint> getStyleableProperty(JFXComboBox n) { final JFXComboBoxListViewSkin<?> skin = (JFXComboBoxListViewSkin<?>) n.getSkin(); return (StyleableProperty<Paint>) skin.promptTextFill; } };
@Override public StyleableProperty<Paint> getStyleableProperty(JFXComboBox<?> control) { return control.focusColorProperty(); } };
@Override public final void setDisableAnimation(final Boolean disabled) { this.disableAnimationProperty().set(disabled); }
@Override public boolean isSettable(JFXComboBox n) { final JFXComboBoxListViewSkin<?> skin = (JFXComboBoxListViewSkin<?>) n.getSkin(); return skin.promptTextFill == null || !skin.promptTextFill.isBound(); }