List of usage examples for javafx.scene.control ListCell ListCell
public ListCell()
From source file:Main.java
@Override public void start(Stage stage) { Scene scene = new Scene(new Group(), 200, 200); ComboBox<String> myComboBox = new ComboBox<String>(); myComboBox.getItems().addAll("A", "B", "C", "D", "E"); myComboBox.setCellFactory(new Callback<ListView<String>, ListCell<String>>() { @Override//from w w w . j a v a 2s . com public ListCell<String> call(ListView<String> param) { final ListCell<String> cell = new ListCell<String>() { { super.setPrefWidth(100); } @Override public void updateItem(String item, boolean empty) { super.updateItem(item, empty); if (item != null) { setText(item); if (item.contains("A")) { setTextFill(Color.RED); } else if (item.contains("B")) { setTextFill(Color.GREEN); } else { setTextFill(Color.BLACK); } } else { setText(null); } } }; return cell; } }); Group root = (Group) scene.getRoot(); root.getChildren().add(myComboBox); stage.setScene(scene); stage.show(); }
From source file:Main.java
@Override public void start(final Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root, 400, 300, Color.WHITE); GridPane gridpane = new GridPane(); ComboBox<Color> cmb = new ComboBox<Color>(); cmb.getItems().addAll(Color.RED, Color.GREEN, Color.BLUE); cmb.setCellFactory(new Callback<ListView<Color>, ListCell<Color>>() { @Override/*from w w w.ja va 2 s. c o m*/ public ListCell<Color> call(ListView<Color> p) { return new ListCell<Color>() { private final Rectangle rectangle; { setContentDisplay(ContentDisplay.GRAPHIC_ONLY); rectangle = new Rectangle(10, 10); } @Override protected void updateItem(Color item, boolean empty) { super.updateItem(item, empty); if (item == null || empty) { setGraphic(null); } else { rectangle.setFill(item); setGraphic(rectangle); } } }; } }); gridpane.add(cmb, 2, 0); root.getChildren().add(gridpane); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(final Stage primaryStage) { primaryStage.setTitle(""); Group root = new Group(); Scene scene = new Scene(root, 400, 300, Color.WHITE); GridPane gridpane = new GridPane(); ComboBox<Color> cmb = new ComboBox<Color>(); cmb.getItems().addAll(Color.RED, Color.GREEN, Color.BLUE); cmb.setCellFactory(new Callback<ListView<Color>, ListCell<Color>>() { @Override/*w ww .j a va 2s. c om*/ public ListCell<Color> call(ListView<Color> p) { return new ListCell<Color>() { private final Rectangle rectangle; { setContentDisplay(ContentDisplay.GRAPHIC_ONLY); rectangle = new Rectangle(10, 10); } @Override protected void updateItem(Color item, boolean empty) { super.updateItem(item, empty); if (item == null || empty) { setGraphic(null); } else { rectangle.setFill(item); setGraphic(rectangle); } } }; } }); gridpane.add(cmb, 2, 0); root.getChildren().add(gridpane); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { stage.setTitle("ComboBoxSample"); Scene scene = new Scene(new Group(), 450, 250); ComboBox emailComboBox = new ComboBox(); emailComboBox.getItems().addAll("A", "B", "C", "D", "E"); emailComboBox.setCellFactory(new Callback<ListView<String>, ListCell<String>>() { @Override/* w w w. j a v a2s . c om*/ public ListCell<String> call(ListView<String> param) { final ListCell<String> cell = new ListCell<String>() { { super.setPrefWidth(100); } @Override public void updateItem(String item, boolean empty) { super.updateItem(item, empty); if (item != null) { setText(item); if (item.contains("A")) { setTextFill(Color.RED); } else if (item.contains("B")) { setTextFill(Color.GREEN); } else { setTextFill(Color.BLACK); } } else { setText(null); } } }; return cell; } }); GridPane grid = new GridPane(); grid.setVgap(4); grid.setHgap(10); grid.setPadding(new Insets(5, 5, 5, 5)); grid.add(new Label("To: "), 0, 0); grid.add(emailComboBox, 1, 0); Group root = (Group) scene.getRoot(); root.getChildren().add(grid); stage.setScene(scene); stage.show(); }
From source file:Main.java
private ListView<Person> createLeaderListView(ObservableList<Person> leaders) { final ListView<Person> leaderListView = new ListView<>(leaders); leaderListView.setPrefWidth(150);//w w w. j ava 2 s . c om leaderListView.setMaxWidth(Double.MAX_VALUE); leaderListView.setPrefHeight(150); leaderListView.setCellFactory(new Callback<ListView<Person>, ListCell<Person>>() { @Override public ListCell<Person> call(ListView<Person> param) { Tooltip tooltip = new Tooltip(); ListCell<Person> cell = new ListCell<Person>() { @Override public void updateItem(Person item, boolean empty) { super.updateItem(item, empty); if (item != null) { // leadLbl.setText(item.getAliasName()); setText(item.getFirstName() + " " + item.getLastName()); tooltip.setText(item.getAliasName()); setTooltip(tooltip); } } }; return cell; } }); return leaderListView; }
From source file:Person.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle(""); Group root = new Group(); Scene scene = new Scene(root, 500, 250, Color.WHITE); // create a grid pane GridPane gridpane = new GridPane(); gridpane.setPadding(new Insets(5)); gridpane.setHgap(10);/* ww w. ja v a2 s.com*/ gridpane.setVgap(10); ObservableList<Person> leaders = FXCollections.observableArrayList(); leaders.add(new Person("A", "B", "C")); leaders.add(new Person("D", "E", "F")); final ListView<Person> leaderListView = new ListView<Person>(leaders); leaderListView.setPrefWidth(150); leaderListView.setPrefHeight(150); // leaderListView.setCellFactory(new Callback<ListView<Person>, ListCell<Person>>() { public ListCell<Person> call(ListView<Person> param) { final Label leadLbl = new Label(); final Tooltip tooltip = new Tooltip(); final ListCell<Person> cell = new ListCell<Person>() { @Override public void updateItem(Person item, boolean empty) { super.updateItem(item, empty); if (item != null) { leadLbl.setText(item.getAliasName()); setText(item.getFirstName() + " " + item.getLastName()); tooltip.setText(item.getAliasName()); setTooltip(tooltip); } } }; // ListCell return cell; } }); // setCellFactory gridpane.add(leaderListView, 0, 1); leaderListView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Person>() { public void changed(ObservableValue<? extends Person> observable, Person oldValue, Person newValue) { System.out.println("selection changed"); } }); root.getChildren().add(gridpane); primaryStage.setScene(scene); primaryStage.show(); }
From source file:eu.ggnet.dwoss.receipt.shipment.ShipmentUpdateStage.java
private void init(Shipment s) { okButton.setOnAction((ActionEvent event) -> { shipment = getShipment();/* w ww. j a va 2s. com*/ if (isValid()) close(); }); cancelButton.setOnAction((ActionEvent event) -> { close(); }); idField = new TextField(Long.toString(s.getId())); idField.setDisable(true); shipIdField = new TextField(s.getShipmentId()); Callback<ListView<TradeName>, ListCell<TradeName>> cb = new Callback<ListView<TradeName>, ListCell<TradeName>>() { @Override public ListCell<TradeName> call(ListView<TradeName> param) { return new ListCell<TradeName>() { @Override protected void updateItem(TradeName item, boolean empty) { super.updateItem(item, empty); if (item == null || empty) setText("Hersteller whlen..."); else setText(item.getName()); } }; } }; Set<TradeName> contractors = Client.lookup(MandatorSupporter.class).loadContractors().all(); ownerBox = new ComboBox<>(FXCollections.observableArrayList(contractors)); ownerBox.setMaxWidth(MAX_VALUE); ownerBox.setCellFactory(cb); ownerBox.getSelectionModel().selectedItemProperty().addListener( (ObservableValue<? extends TradeName> observable, TradeName oldValue, TradeName newValue) -> { if (newValue == null) return; shipment.setContractor(newValue); manufacturerBox.getSelectionModel().select(newValue.getManufacturer()); }); ObservableList<TradeName> manufacturers = FXCollections.observableArrayList(TradeName.getManufacturers()); manufacturerBox = new ComboBox<>(manufacturers); manufacturerBox.setMaxWidth(MAX_VALUE); manufacturerBox.setCellFactory(cb); SingleSelectionModel<TradeName> sm = ownerBox.getSelectionModel(); if (s.getContractor() == null) sm.selectFirst(); else sm.select(s.getContractor()); if (shipment.getDefaultManufacturer() != null) manufacturerBox.getSelectionModel().select(shipment.getDefaultManufacturer()); statusBox = new ComboBox<>(FXCollections.observableArrayList(Shipment.Status.values())); statusBox.setMaxWidth(MAX_VALUE); statusBox.getSelectionModel().select(s.getStatus() == null ? OPENED : s.getStatus()); GridPane grid = new GridPane(); grid.addRow(1, new Label("ID:"), idField); grid.addRow(2, new Label("Shipment ID:"), shipIdField); grid.addRow(3, new Label("Besitzer:"), ownerBox); grid.addRow(4, new Label("Hersteller:"), manufacturerBox); grid.addRow(5, new Label("Status"), statusBox); grid.setMaxWidth(MAX_VALUE); grid.vgapProperty().set(2.); grid.getColumnConstraints().add(0, new ColumnConstraints(100, 100, Double.MAX_VALUE, Priority.SOMETIMES, HPos.LEFT, false)); grid.getColumnConstraints().add(1, new ColumnConstraints(100, 150, Double.MAX_VALUE, Priority.ALWAYS, HPos.LEFT, true)); HBox hButtonBox = new HBox(okButton, cancelButton); hButtonBox.alignmentProperty().set(Pos.TOP_RIGHT); errorLabel.setWrapText(true); BorderPane rootPane = new BorderPane(grid, errorLabel, null, hButtonBox, null); this.setTitle(s.getId() > 0 ? "Shipment bearbeiten" : "Shipment anlegen"); this.setScene(new Scene(rootPane)); this.setResizable(false); }
From source file:com.rvantwisk.cnctools.controllers.ToolConfigurationsController.java
@FXML void initialize() { v_toolsList.setItems(toolDBManager.getToolDB()); setMode(this.mode); // toolConfig.con toolParameters.disableProperty().bind(v_toolsList.getSelectionModel().selectedItemProperty().isNull()); btnCopy.disableProperty().bind(v_toolsList.getSelectionModel().selectedItemProperty().isNull()); btnDelete.disableProperty().bind(v_toolsList.getSelectionModel().selectedItemProperty().isNull()); // When the user selects a item in the list then update the tool panel v_toolsList.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<ToolParameter>() { @Override/*from www . jav a 2 s. c om*/ public void changed(ObservableValue<? extends ToolParameter> observable, ToolParameter oldValue, ToolParameter newValue) { if (v_toolsList.getSelectionModel().selectedItemProperty().get() == null) { toolParameters.setTool(null); // toolParametersController.setTool(new ToolParameter("", ToolParameter.Units.MM, new EndMill(6.0))); } else { toolParameters.setTool(newValue); } } }); // Set text in ListView v_toolsList.setCellFactory(new Callback<ListView<ToolParameter>, ListCell<ToolParameter>>() { @Override public ListCell<ToolParameter> call(ListView<ToolParameter> p) { ListCell<ToolParameter> cell = new ListCell<ToolParameter>() { @Override protected void updateItem(ToolParameter t, boolean bln) { super.updateItem(t, bln); this.textProperty().unbind(); if (t != null) { textProperty().bind(t.nameProperty()); } else { textProperty().setValue(""); } } }; return cell; } }); }
From source file:com.rvantwisk.cnctools.controllers.PostProcessorsController.java
@FXML void initialize() { v_postprocessorList.setItems(projectModel.postProcessorsProperty()); if (mode == Mode.SELECT) { btnUse.setVisible(true);// www . ja v a2 s . co m } else { btnUse.setVisible(false); } // toolConfig.con postProcessor.disableProperty() .bind(v_postprocessorList.getSelectionModel().selectedItemProperty().isNull()); btnCopy.disableProperty().bind(v_postprocessorList.getSelectionModel().selectedItemProperty().isNull()); btnDelete.disableProperty().bind(v_postprocessorList.getSelectionModel().selectedItemProperty().isNull()); // When the user selects a item in the list then update the tool panel v_postprocessorList.getSelectionModel().selectedItemProperty() .addListener(new ChangeListener<CNCToolsPostProcessConfig>() { @Override public void changed(ObservableValue<? extends CNCToolsPostProcessConfig> observable, CNCToolsPostProcessConfig oldValue, CNCToolsPostProcessConfig newValue) { if (v_postprocessorList.getSelectionModel().selectedItemProperty().get() == null) { postProcessor.setData(null); // toolParametersController.setTool(new ToolParameter("", ToolParameter.Units.MM, new EndMill(6.0))); } else { postProcessor.setData(newValue); } } }); // Set text in ListView v_postprocessorList.setCellFactory( new Callback<ListView<CNCToolsPostProcessConfig>, ListCell<CNCToolsPostProcessConfig>>() { @Override public ListCell<CNCToolsPostProcessConfig> call(ListView<CNCToolsPostProcessConfig> p) { ListCell<CNCToolsPostProcessConfig> cell = new ListCell<CNCToolsPostProcessConfig>() { @Override protected void updateItem(CNCToolsPostProcessConfig t, boolean bln) { super.updateItem(t, bln); this.textProperty().unbind(); if (t != null) { textProperty().bind(t.nameProperty()); } else { textProperty().setValue(""); } } }; return cell; } }); int index = projectModel.postProcessorsProperty().indexOf(postProcessConfig); v_postprocessorList.getSelectionModel().select(index); }
From source file:gov.va.isaac.gui.preferences.plugins.properties.PreferencesPluginComboBoxProperty.java
/** * @param name// ww w . j av a 2 s . c om * @param stringConverter * * Constructor for ComboBox that displays a String * that must be derived/converted from its underlying value * * Allows a preexisting Label to be used */ protected PreferencesPluginComboBoxProperty(Label label, StringConverter<T> stringConverter) { super(label, new ComboBox<T>(), new SimpleObjectProperty<T>(), null, // validator handled below stringConverter, new PropertyAction<T, ComboBox<T>>() { @Override public void apply(PreferencesPluginProperty<T, ComboBox<T>> property) { property.getProperty() .bind(property.getControl().getSelectionModel().selectedItemProperty()); } }, new PropertyAction<T, ComboBox<T>>() { @Override public void apply(PreferencesPluginProperty<T, ComboBox<T>> property) { property.getControl().getSelectionModel().select(property.readFromPersistedPreferences()); } }, new PropertyAction<T, ComboBox<T>>() { @Override public void apply(PreferencesPluginProperty<T, ComboBox<T>> property) { GridPane.setHgrow(property.getLabel(), Priority.NEVER); GridPane.setFillWidth(property.getControl(), true); GridPane.setHgrow(property.getControl(), Priority.ALWAYS); } }); validator = new ValidBooleanBinding() { { bind(getProperty()); setComputeOnInvalidate(true); } @Override protected boolean computeValue() { if (getProperty().getValue() == null) { this.setInvalidReason("null/unset/unselected " + name); logger.debug(getReasonWhyInvalid().get()); TextErrorColorHelper.setTextErrorColor(label); return false; } else { TextErrorColorHelper.clearTextErrorColor(label); } if (StringUtils.isEmpty(getStringConverter().convertToString(getProperty().getValue()))) { this.setInvalidReason("Invalid " + name); logger.debug(getReasonWhyInvalid().get()); TextErrorColorHelper.setTextErrorColor(label); return false; } else { TextErrorColorHelper.clearTextErrorColor(label); } this.clearInvalidReason(); return true; } }; control.setCellFactory(new Callback<ListView<T>, ListCell<T>>() { @Override public ListCell<T> call(ListView<T> param) { final ListCell<T> cell = new ListCell<T>() { @Override protected void updateItem(T c, boolean emptyRow) { super.updateItem(c, emptyRow); if (c == null) { setText(null); } else { String diplay = getStringConverter().convertToString(c); setText(diplay); } } }; return cell; } }); control.setButtonCell(new ListCell<T>() { @Override protected void updateItem(T c, boolean emptyRow) { super.updateItem(c, emptyRow); if (emptyRow) { setText(""); } else { String diplay = getStringConverter().convertToString(c); setText(diplay); } } }); }