Java Code Examples for javafx.scene.control.ComboBox#setEditable()
The following examples show how to use
javafx.scene.control.ComboBox#setEditable() .
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: GenericRootAndDatasetStructure.java From paintera with GNU General Public License v2.0 | 6 votes |
private Node createNode() { final Node groupField = rootNode.get(); final ComboBox<String> datasetDropDown = new ComboBox<>(datasetChoices); datasetDropDown.setPromptText(datasetPromptText); datasetDropDown.setEditable(false); datasetDropDown.valueProperty().bindBidirectional(dataset); datasetDropDown.disableProperty().bind(this.isDropDownReady); final GridPane grid = new GridPane(); grid.add(groupField, 0, 0); grid.add(datasetDropDown, 0, 1); GridPane.setHgrow(groupField, Priority.ALWAYS); GridPane.setHgrow(datasetDropDown, Priority.ALWAYS); final Button button = new Button("Browse"); button.setOnAction(event -> onBrowseClicked.accept(grid.getScene())); grid.add(button, 1, 0); return grid; }
Example 2
Source File: ComboBoxSample.java From marathonv5 with Apache License 2.0 | 6 votes |
public ComboBoxSample() { HBox hbox = HBoxBuilder.create().alignment(Pos.CENTER).spacing(15).build(); //Non-editable combobox. Created with a builder ComboBox uneditableComboBox = ComboBoxBuilder.create() .id("uneditable-combobox") .promptText("Make a choice...") .items(FXCollections.observableArrayList(strings.subList(0, 8))).build(); //Editable combobox. Use the default item display length ComboBox<String> editableComboBox = new ComboBox<String>(); editableComboBox.setId("second-editable"); editableComboBox.setPromptText("Edit or Choose..."); editableComboBox.setItems(strings); editableComboBox.setEditable(true); hbox.getChildren().addAll(uneditableComboBox, editableComboBox); getChildren().add(hbox); }
Example 3
Source File: ComboBoxSample.java From marathonv5 with Apache License 2.0 | 6 votes |
public ComboBoxSample() { HBox hbox = HBoxBuilder.create().alignment(Pos.CENTER).spacing(15).build(); //Non-editable combobox. Created with a builder ComboBox uneditableComboBox = ComboBoxBuilder.create() .id("uneditable-combobox") .promptText("Make a choice...") .items(FXCollections.observableArrayList(strings.subList(0, 8))).build(); //Editable combobox. Use the default item display length ComboBox<String> editableComboBox = new ComboBox<String>(); editableComboBox.setId("second-editable"); editableComboBox.setPromptText("Edit or Choose..."); editableComboBox.setItems(strings); editableComboBox.setEditable(true); hbox.getChildren().addAll(uneditableComboBox, editableComboBox); getChildren().add(hbox); }
Example 4
Source File: GroupAndDatasetStructure.java From paintera with GNU General Public License v2.0 | 5 votes |
public Node createNode() { final TextField groupField = new TextField(group.getValue()); groupField.setMinWidth(0); groupField.setMaxWidth(Double.POSITIVE_INFINITY); groupField.setPromptText(groupPromptText); groupField.textProperty().bindBidirectional(group); final ComboBox<String> datasetDropDown = new ComboBox<>(datasetChoices); datasetDropDown.setPromptText(datasetPromptText); datasetDropDown.setEditable(false); datasetDropDown.valueProperty().bindBidirectional(dataset); datasetDropDown.setMinWidth(groupField.getMinWidth()); datasetDropDown.setPrefWidth(groupField.getPrefWidth()); datasetDropDown.setMaxWidth(groupField.getMaxWidth()); datasetDropDown.disableProperty().bind(this.isDropDownReady); final GridPane grid = new GridPane(); grid.add(groupField, 0, 0); grid.add(datasetDropDown, 0, 1); GridPane.setHgrow(groupField, Priority.ALWAYS); GridPane.setHgrow(datasetDropDown, Priority.ALWAYS); final Button button = new Button("Browse"); button.setOnAction(event -> { Optional.ofNullable(onBrowseClicked.apply(group.getValue(), grid.getScene())).ifPresent(group::setValue); }); grid.add(button, 1, 0); groupField.effectProperty().bind( Bindings.createObjectBinding( () -> groupField.isFocused() ? this.textFieldNoErrorEffect : groupErrorEffect.get(), groupErrorEffect, groupField.focusedProperty() )); return grid; }
Example 5
Source File: SetCustomController.java From Spring-generator with MIT License | 5 votes |
/** * 添加自定义属性 * * @param event */ public void onAddPropertyToTable(ActionEvent event) { LOG.debug("执行添加自定义属性..."); ComboBox<String> comboBox = new ComboBox<>(); comboBox.promptTextProperty().bind(Main.LANGUAGE.get(LanguageKey.SET_CBO_TEMPLATE)); comboBox.prefWidthProperty().bind(tdTemplate.widthProperty()); comboBox.setEditable(true); comboBox.getItems().addAll(indexController.getTemplateNameItems()); TableAttributeKeyValueTemplate attribute = new TableAttributeKeyValueTemplate(txtKey.getText(), txtPackageName.getText(), txtClassName.getText(), Constant.JAVA_SUFFIX, comboBox); tblPropertyValues.add(attribute); LOG.debug("添加自定义属性-->成功!"); }
Example 6
Source File: SetCustomController.java From Vert.X-generator with MIT License | 5 votes |
/** * 添加自定义属性 * * @param event */ public void onAddPropertyToTable(ActionEvent event) { LOG.debug("执行添加自定义属性..."); ComboBox<String> comboBox = new ComboBox<>(); comboBox.promptTextProperty().bind(Main.LANGUAGE.get(LanguageKey.SET_CBO_TEMPLATE)); comboBox.prefWidthProperty().bind(tdTemplate.widthProperty()); comboBox.setEditable(true); comboBox.getItems().addAll(indexController.getTemplateNameItems()); TableAttributeKeyValueTemplate attribute = new TableAttributeKeyValueTemplate(txtKey.getText(), txtPackageName.getText(), txtClassName.getText(), Constant.JAVA_SUFFIX, comboBox); tblPropertyValues.add(attribute); LOG.debug("添加自定义属性-->成功!"); }
Example 7
Source File: FlyoutDemo.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Creates and returns demo widget * @return the control for demo-ing widget */ public GridPane getStuffControl() { GridPane gp = new GridPane(); gp.setPadding(new Insets(5, 5, 5, 5)); gp.setHgap(5); ComboBox<String> stuffCombo = new ComboBox<>(); stuffCombo.setEditable(true); stuffCombo.setPromptText("Add stuff..."); stuffCombo.getItems().addAll( "Stuff", "contained", "within", "the", "combo" ); Label l = new Label("Select or enter example text:"); l.setFont(Font.font(l.getFont().getFamily(), 10)); l.setTextFill(Color.WHITE); Button add = new Button("Add"); add.setOnAction(e -> stuffCombo.getItems().add(stuffCombo.getSelectionModel().getSelectedItem())); Button del = new Button("Clear"); del.setOnAction(e -> stuffCombo.getSelectionModel().clearSelection()); gp.add(l, 0, 0, 2, 1); gp.add(stuffCombo, 0, 1, 2, 1); gp.add(add, 2, 1); gp.add(del, 3, 1); return gp; }
Example 8
Source File: ComboRepresentation.java From phoebus with Eclipse Public License 1.0 | 4 votes |
@Override public ComboBox<String> createJFXNode() throws Exception { final ComboBox<String> combo = new ComboBox<>(); if (! toolkit.isEditMode()) { // 'editable' cannot be changed at runtime combo.setEditable(model_widget.propEditable().getValue()); // Handle user's selection combo.setOnAction((event)-> { // We are updating the UI, ignore if (active) return; final String value = combo.getValue(); if (value != null) { // Restore current value contentChanged(null, null, null); // ... which should soon be replaced by updated value, if accepted Platform.runLater(() -> confirm(value)); } }); // Also write to PV when user re-selects the current value combo.setCellFactory(list -> { final ListCell<String> cell = new ListCell<>() { @Override public void updateItem(final String item, final boolean empty) { super.updateItem(item, empty); if ( !empty ) setText(item); } }; cell.addEventFilter(MouseEvent.MOUSE_PRESSED, e -> { // Is this a click on the 'current' value which would by default be ignored? if (Objects.equals(combo.getValue(), cell.getItem())) { combo.fireEvent(new ActionEvent()); // Alternatively... //combo.setValue(null); //combo.getSelectionModel().select(cell.getItem()); e.consume(); } }); return cell; }); combo.setOnMouseClicked(event -> { // Secondary mouse button should bring up context menu, // but not show selections (i.e. not expand drop-down). if(event.getButton().equals(MouseButton.SECONDARY)){ combo.hide(); } }); } contentChanged(null, null, null); return combo; }
Example 9
Source File: DisplayEditor.java From phoebus with Eclipse Public License 1.0 | 4 votes |
private ToolBar createToolbar() { final Button[] undo_redo = UndoButtons.createButtons(undo); final ComboBox<String> zoom_levels = new ComboBox<>(); zoom_levels.getItems().addAll(JFXRepresentation.ZOOM_LEVELS); zoom_levels.setEditable(true); zoom_levels.setValue(JFXRepresentation.DEFAULT_ZOOM_LEVEL); zoom_levels.setTooltip(new Tooltip(Messages.SelectZoomLevel)); zoom_levels.setPrefWidth(100.0); // For Ctrl-Wheel zoom gesture zoomListener zl = new zoomListener(zoom_levels); toolkit.setZoomListener(zl); zoom_levels.setOnAction(event -> { final String before = zoom_levels.getValue(); if (before == null) return; final String actual = requestZoom(before); // Java 9 results in IndexOutOfBoundException // when combo is updated within the action handler, // so defer to another UI tick Platform.runLater(() -> zoom_levels.setValue(actual)); }); final MenuButton order = new MenuButton(null, null, createMenuItem(ActionDescription.TO_BACK), createMenuItem(ActionDescription.MOVE_UP), createMenuItem(ActionDescription.MOVE_DOWN), createMenuItem(ActionDescription.TO_FRONT)); order.setTooltip(new Tooltip(Messages.Order)); final MenuButton align = new MenuButton(null, null, createMenuItem(ActionDescription.ALIGN_LEFT), createMenuItem(ActionDescription.ALIGN_CENTER), createMenuItem(ActionDescription.ALIGN_RIGHT), createMenuItem(ActionDescription.ALIGN_TOP), createMenuItem(ActionDescription.ALIGN_MIDDLE), createMenuItem(ActionDescription.ALIGN_BOTTOM), createMenuItem(ActionDescription.ALIGN_GRID)); align.setTooltip(new Tooltip(Messages.Align)); final MenuButton size = new MenuButton(null, null, createMenuItem(ActionDescription.MATCH_WIDTH), createMenuItem(ActionDescription.MATCH_HEIGHT)); size.setTooltip(new Tooltip(Messages.Size)); final MenuButton dist = new MenuButton(null, null, createMenuItem(ActionDescription.DIST_HORIZ), createMenuItem(ActionDescription.DIST_VERT)); dist.setTooltip(new Tooltip(Messages.Distribute)); // Use the first item as the icon for the drop-down... try { order.setGraphic(ImageCache.getImageView(ActionDescription.TO_BACK.getIconResourcePath())); align.setGraphic(ImageCache.getImageView(ActionDescription.ALIGN_LEFT.getIconResourcePath())); size.setGraphic(ImageCache.getImageView(ActionDescription.MATCH_WIDTH.getIconResourcePath())); dist.setGraphic(ImageCache.getImageView(ActionDescription.DIST_HORIZ.getIconResourcePath())); } catch (Exception ex) { logger.log(Level.WARNING, "Cannot load icon", ex); } return new ToolBar( grid = createToggleButton(ActionDescription.ENABLE_GRID), snap = createToggleButton(ActionDescription.ENABLE_SNAP), coords = createToggleButton(ActionDescription.ENABLE_COORDS), new Separator(), order, align, size, dist, new Separator(), undo_redo[0], undo_redo[1], new Separator(), zoom_levels); }
Example 10
Source File: BackSpace.java From JavaFX with MIT License | 4 votes |
@Override public void start(Stage stage) { stage.setTitle("ComboBox"); // non-editable column VBox nonEditBox = new VBox(15); ComboBox comboBox1 = new ComboBox(); comboBox1.setEditable(true); comboBox1.setItems(FXCollections.observableArrayList(strings.subList(0, 4))); comboBox1.sceneProperty().addListener(new InvalidationListener() { @Override public void invalidated(Observable arg0) { System.out.println("sceneProperty changed!"); } }); nonEditBox.getChildren().add(comboBox1); ComboBox comboBox2 = new ComboBox(); comboBox2.setEditable(true); comboBox2.setItems(FXCollections.observableArrayList(strings.subList(0, 5))); nonEditBox.getChildren().add(comboBox2); TextField textField1 = new TextField(); nonEditBox.getChildren().add(textField1); nonEditBox.addEventHandler(KeyEvent.ANY, new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent keyEvent) { if (keyEvent.getCode().equals(KeyCode.BACK_SPACE) || keyEvent.getCode().equals(KeyCode.DELETE)) { System.out.println("VBox is receiving key event !"); } } }); HBox vbox = new HBox(20); vbox.setLayoutX(40); vbox.setLayoutY(25); vbox.getChildren().addAll(nonEditBox); Scene scene = new Scene(new Group(vbox), 620, 190); stage.setScene(scene); stage.show(); // scene.impl_focusOwnerProperty().addListener(new // ChangeListener<Node>() { // public void changed(ObservableValue<? extends Node> ov, Node t, Node // t1) { // System.out.println("focus moved from " + t + " to " + t1); // } // }); }