Java Code Examples for javafx.scene.control.ComboBox#setCellFactory()
The following examples show how to use
javafx.scene.control.ComboBox#setCellFactory() .
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: ColorInputPane.java From constellation with Apache License 2.0 | 8 votes |
private ComboBox<ConstellationColor> makeNamedCombo() { final ObservableList<ConstellationColor> namedColors = FXCollections.observableArrayList(); for (final ConstellationColor c : ConstellationColor.NAMED_COLOR_LIST) { namedColors.add(c); } final ComboBox<ConstellationColor> namedCombo = new ComboBox<>(namedColors); namedCombo.setValue(ConstellationColor.WHITE); final Callback<ListView<ConstellationColor>, ListCell<ConstellationColor>> cellFactory = (final ListView<ConstellationColor> p) -> new ListCell<ConstellationColor>() { @Override protected void updateItem(final ConstellationColor item, boolean empty) { super.updateItem(item, empty); if (item != null) { final Rectangle r = new Rectangle(12, 12, item.getJavaFXColor()); r.setStroke(Color.BLACK); setText(item.getName()); setGraphic(r); } } }; namedCombo.setCellFactory(cellFactory); namedCombo.setButtonCell(cellFactory.call(null)); return namedCombo; }
Example 2
Source File: TraceAUtilityNetworkController.java From arcgis-runtime-samples-java with Apache License 2.0 | 6 votes |
/** * Prompts the user to select a terminal from a provided list. * * @param terminals a list of terminals for the user to choose from * @return the user's selected terminal */ private Optional<UtilityTerminal> promptForTerminalSelection(List<UtilityTerminal> terminals) { // create a dialog for terminal selection ChoiceDialog<UtilityTerminal> utilityTerminalSelectionDialog = new ChoiceDialog<>(terminals.get(0), terminals); utilityTerminalSelectionDialog.initOwner(mapView.getScene().getWindow()); utilityTerminalSelectionDialog.setTitle("Choose Utility Terminal"); utilityTerminalSelectionDialog.setHeaderText("Junction selected. Choose the Utility Terminal to add as the trace element:"); // override the list cell in the dialog's combo box to show the terminal name @SuppressWarnings("unchecked") ComboBox<UtilityTerminal> comboBox = (ComboBox<UtilityTerminal>) ((GridPane) utilityTerminalSelectionDialog.getDialogPane() .getContent()).getChildren().get(1); comboBox.setCellFactory(param -> new UtilityTerminalListCell()); comboBox.setButtonCell(new UtilityTerminalListCell()); // show the terminal selection dialog and capture the user selection return utilityTerminalSelectionDialog.showAndWait(); }
Example 3
Source File: DeckShipPane.java From logbook-kai with MIT License | 6 votes |
/** * 装備の初期設定 * * @param list * @param image * @param label */ private void installItemName(ComboBox<SlotitemMst> list, ImageView image, Label label) { list.setConverter(itemNameStringConverter); list.setCellFactory(e -> new ItemNameCell()); // 装備が選ばれた時のリスナー list.getSelectionModel().selectedItemProperty().addListener((ov, o, n) -> { if (this.initialized) { // 装備の変更を検知 this.modified.set(true); } image.setImage(Items.itemImage(n)); label.setText(itemNameStringConverter.toString(n)); }); Map<Integer, SlotitemMst> itemMstMap = SlotitemMstCollection.get().getSlotitemMap(); list.getItems().addAll(SlotItemCollection.get() .getSlotitemMap() .values() .stream() .map(SlotItem::getSlotitemId) .distinct() .map(itemMstMap::get) .sorted(Comparator.comparing(SlotitemMst::getName)) .sorted(Comparator.comparing(m -> m.getType().get(3))) .collect(Collectors.toList())); }
Example 4
Source File: AudioConfigurationView.java From beatoraja with GNU General Public License v3.0 | 5 votes |
private void initComboBox(ComboBox<Integer> combo, final String[] values) { combo.setCellFactory((param) -> new OptionListCell(values)); combo.setButtonCell(new OptionListCell(values)); for (int i = 0; i < values.length; i++) { combo.getItems().add(i); } }
Example 5
Source File: IRConfigurationView.java From beatoraja with GNU General Public License v3.0 | 5 votes |
private void initComboBox(ComboBox<Integer> combo, final String[] values) { combo.setCellFactory((param) -> new OptionListCell(values)); combo.setButtonCell(new OptionListCell(values)); for (int i = 0; i < values.length; i++) { combo.getItems().add(i); } }
Example 6
Source File: MainView.java From bisq with GNU Affero General Public License v3.0 | 5 votes |
private Tuple2<ComboBox<PriceFeedComboBoxItem>, VBox> getMarketPriceBox() { VBox marketPriceBox = new VBox(); marketPriceBox.setAlignment(Pos.CENTER_LEFT); ComboBox<PriceFeedComboBoxItem> priceComboBox = new JFXComboBox<>(); priceComboBox.setVisibleRowCount(12); priceComboBox.setFocusTraversable(false); priceComboBox.setId("price-feed-combo"); priceComboBox.setPadding(new Insets(0, -4, -4, 0)); priceComboBox.setCellFactory(p -> getPriceFeedComboBoxListCell()); ListCell<PriceFeedComboBoxItem> buttonCell = getPriceFeedComboBoxListCell(); buttonCell.setId("price-feed-combo"); priceComboBox.setButtonCell(buttonCell); Label marketPriceLabel = new Label(); updateMarketPriceLabel(marketPriceLabel); marketPriceLabel.getStyleClass().add("nav-balance-label"); marketPriceLabel.setPadding(new Insets(-2, 0, 4, 9)); marketPriceBox.getChildren().addAll(priceComboBox, marketPriceLabel); model.getMarketPriceUpdated().addListener((observable, oldValue, newValue) -> updateMarketPriceLabel(marketPriceLabel)); return new Tuple2<>(priceComboBox, marketPriceBox); }
Example 7
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 8
Source File: ComboBoxFX.java From mars-sim with GNU General Public License v3.0 | 4 votes |
@Override public void start(Stage stage) { HBox box = new HBox(); ComboBox<ComboBoxItem> cb = new ComboBox<ComboBoxItem>(); cb.setCellFactory(e -> new ListCell<ComboBoxItem>() { @Override public void updateItem(ComboBoxItem item, boolean empty) { super.updateItem(item, empty); if (empty) { setText(null); setDisable(false); } else { setText(item.toString()); // If item is a header we disable it. setDisable(!item.isHeader()); // If item is a header we add a style to it so it looks like a header. if (item.isHeader()) { setStyle("-fx-font-weight: bold;"); } else { setStyle("-fx-font-weight: normal;"); } } } }); ObservableList<ComboBoxItem> items = FXCollections.observableArrayList( new ComboBoxItem("Labels", true), new ComboBoxItem("Building", false), new ComboBoxItem("Vehicle", false) ); cb.getItems().addAll(items); box.getChildren().add(cb); stage.setScene(new Scene(box)); stage.show(); }
Example 9
Source File: FeatureLayerExtrusionSample.java From arcgis-runtime-samples-java with Apache License 2.0 | 4 votes |
@Override public void start(Stage stage) { StackPane stackPane = new StackPane(); Scene fxScene = new Scene(stackPane); // for adding styling to any controls that are added fxScene.getStylesheets().add(getClass().getResource("/feature_layer_extrusion/style.css").toExternalForm()); // set title, size, and add scene to stage stage.setTitle("Feature Layer Extrusion Sample"); stage.setWidth(800); stage.setHeight(700); stage.setScene(fxScene); stage.show(); // so scene can be visible within application ArcGISScene scene = new ArcGISScene(Basemap.createTopographic()); sceneView = new SceneView(); sceneView.setArcGISScene(scene); stackPane.getChildren().add(sceneView); // get us census data as a service feature table ServiceFeatureTable statesServiceFeatureTable = new ServiceFeatureTable("https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3"); // creates feature layer from table and add to scene final FeatureLayer statesFeatureLayer = new FeatureLayer(statesServiceFeatureTable); // feature layer must be rendered dynamically for extrusion to work statesFeatureLayer.setRenderingMode(FeatureLayer.RenderingMode.DYNAMIC); scene.getOperationalLayers().add(statesFeatureLayer); // symbols are used to display features (US states) from table SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xFF000000, 1.0f); SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0xFF0000FF, lineSymbol); final SimpleRenderer renderer = new SimpleRenderer(fillSymbol); // set the extrusion mode to absolute height renderer.getSceneProperties().setExtrusionMode(Renderer.SceneProperties.ExtrusionMode.ABSOLUTE_HEIGHT); statesFeatureLayer.setRenderer(renderer); // set camera to focus on state features Point lookAtPoint = new Point(-10974490, 4814376, 0, SpatialReferences.getWebMercator()); sceneView.setViewpointCamera(new Camera(lookAtPoint, 10000000, 0, 20, 0)); // create a combo box to choose between different expressions/attributes to extrude by ComboBox<ExtrusionAttribute> attributeComboBox = new ComboBox<>(); attributeComboBox.setCellFactory(list -> new ListCell<ExtrusionAttribute> (){ @Override protected void updateItem(ExtrusionAttribute attribute, boolean bln) { super.updateItem(attribute, bln); if (attribute != null) { setText(attribute.getName()); } } }); attributeComboBox.setConverter(new StringConverter<ExtrusionAttribute>() { @Override public String toString(ExtrusionAttribute travelMode) { return travelMode != null ? travelMode.getName() : ""; } @Override public ExtrusionAttribute fromString(String fileName) { return null; } }); // scale down outlier populations ExtrusionAttribute populationDensity = new ExtrusionAttribute("Population Density","[POP07_SQMI] * 5000 + 100000"); // scale up density ExtrusionAttribute totalPopulation = new ExtrusionAttribute("Total Population", "[POP2007]/ 10"); attributeComboBox.setItems(FXCollections.observableArrayList(populationDensity, totalPopulation)); stackPane.getChildren().add(attributeComboBox); StackPane.setAlignment(attributeComboBox, Pos.TOP_LEFT); StackPane.setMargin(attributeComboBox, new Insets(10, 0, 0, 10)); // set the extrusion expression on the renderer when one is chosen in the combo box attributeComboBox.getSelectionModel().selectedItemProperty().addListener(e -> { ExtrusionAttribute selectedAttribute = attributeComboBox.getSelectionModel().getSelectedItem(); renderer.getSceneProperties().setExtrusionExpression(selectedAttribute.getExpression()); }); // start with total population selected attributeComboBox.getSelectionModel().select(totalPopulation); }
Example 10
Source File: JFXWidgetCreator.java From latexdraw with GNU General Public License v3.0 | 4 votes |
default <T> void initComboBox(final ComboBox<T> box, final Map<T, Image> map, final T[] values) { final ComboBoxFactoryList<T> factory = new ComboBoxFactoryList<>(map); box.getItems().addAll(values); box.setButtonCell(factory.call(null)); box.setCellFactory(factory); }
Example 11
Source File: DemoUtil.java From RadialFx with GNU Lesser General Public License v3.0 | 4 votes |
public void addGraphicControl(final String title, final ObjectProperty<Node> graphicProperty) { final Node circle = CircleBuilder.create().radius(4).fill(Color.ORANGE).build(); final Node square = RectangleBuilder.create().width(8).height(8).build(); final Node text = TextBuilder.create().text("test").build(); final ComboBox<Node> choices = new ComboBox<Node>(FXCollections.observableArrayList(circle, square, text)); choices.setCellFactory(new Callback<ListView<Node>, ListCell<Node>>() { @Override public ListCell<Node> call(final ListView<Node> param) { final ListCell<Node> cell = new ListCell<Node>() { @Override public void updateItem(final Node item, final boolean empty) { super.updateItem(item, empty); if (item != null) { setText(item.getClass().getSimpleName()); } else { setText(null); } } }; return cell; } }); choices.getSelectionModel().select(0); graphicProperty.bind(choices.valueProperty()); final VBox box = new VBox(); final Text titleText = new Text(title); titleText.textProperty().bind(new StringBinding() { { super.bind(choices.selectionModelProperty()); } @Override protected String computeValue() { return title + " : " + String.valueOf(choices.selectionModelProperty().get().getSelectedItem().getClass().getSimpleName()); } }); box.getChildren().addAll(titleText, choices); getChildren().add(box); }