javafx.scene.control.ListCell Java Examples
The following examples show how to use
javafx.scene.control.ListCell.
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: JFXListViewSkin.java From JFoenix with Apache License 2.0 | 7 votes |
private double estimateHeight() { // compute the border/padding for the list double borderWidth = snapVerticalInsets(); // compute the gap between list cells JFXListView<T> listview = (JFXListView<T>) getSkinnable(); double gap = listview.isExpanded() ? ((JFXListView<T>) getSkinnable()).getVerticalGap() * (getSkinnable().getItems() .size()) : 0; // compute the height of each list cell double cellsHeight = 0; for (int i = 0; i < flow.getCellCount(); i++) { ListCell<T> cell = flow.getCell(i); cellsHeight += cell.getHeight(); } return cellsHeight + gap + borderWidth; }
Example #3
Source File: UIEnumMenuItemTest.java From tcMenu with Apache License 2.0 | 6 votes |
@Test void testEditingTheExistingTestCellThenRemoval(FxRobot robot) throws InterruptedException { // create an appropriate panel and verify the basics are OK createMainPanel(uiSubItem); performAllCommonChecks(enumItem); // first type some new text for the cell that is valid. Check the consumer is updated. ListCell<String> lc = robot.lookup("#enumList .list-cell").query(); simulateListCellEdit(lc, "hello"); checkThatConsumerCalledWith("hello"); // now we add some bad text, and make sure it errors out. simulateListCellEdit(lc, "bad\\"); verifyThat("#uiItemErrors", (Label l)-> l.getText().contains("Choices must not contain speech marks or backslash") && l.isVisible()); }
Example #4
Source File: ListCellTextFieldTest2.java From oim-fx with MIT License | 6 votes |
@Override public void start(Stage primaryStage) throws Exception { StackPane pane = new StackPane(); Scene scene = new Scene(pane, 300, 150); primaryStage.setScene(scene); ObservableList<String> list = FXCollections.observableArrayList( "Item 1", "Item 2", "Item 3", "Item 4"); ListView<String> lv = new ListView<>(list); lv.setCellFactory(new Callback<ListView<String>, ListCell<String>>() { @Override public ListCell<String> call(ListView<String> param) { return new XCell(); } }); pane.getChildren().add(lv); primaryStage.show(); }
Example #5
Source File: DesignerUtil.java From pmd-designer with BSD 2-Clause "Simplified" License | 6 votes |
public static <T> Callback<ListView<T>, ListCell<T>> simpleListCellFactory(Function<T, String> converter, Function<T, String> toolTipMaker) { return collection -> new ListCell<T>() { @Override protected void updateItem(T item, boolean empty) { super.updateItem(item, empty); if (empty || item == null) { setText(null); setGraphic(null); Tooltip.uninstall(this, getTooltip()); } else { setText(converter.apply(item)); Tooltip.install(this, new Tooltip(toolTipMaker.apply(item))); } } }; }
Example #6
Source File: KeyTestingController.java From chvote-1-0 with GNU Affero General Public License v3.0 | 6 votes |
private void customizeCipherTextCellFactory() { cipherTextList.setCellFactory(new Callback<ListView<AuthenticatedBallot>, ListCell<AuthenticatedBallot>>() { @Override public ListCell<AuthenticatedBallot> call(ListView<AuthenticatedBallot> param) { return new ListCell<AuthenticatedBallot>() { @Override protected void updateItem(AuthenticatedBallot item, boolean empty) { super.updateItem(item, empty); if (item != null) { setText(DatatypeConverter.printHexBinary(item.getAuthenticatedEncryptedBallot())); } } }; } }); }
Example #7
Source File: GUIUtil.java From bisq with GNU Affero General Public License v3.0 | 6 votes |
public static ListCell<PaymentMethod> getPaymentMethodButtonCell() { return new ListCell<>() { @Override protected void updateItem(PaymentMethod item, boolean empty) { super.updateItem(item, empty); if (item != null && !empty) { String id = item.getId(); this.getStyleClass().add("currency-label-selected"); if (id.equals(GUIUtil.SHOW_ALL_FLAG)) { setText(Res.get("list.currency.showAll")); } else { setText(Res.get(id)); } } else { setText(""); } } }; }
Example #8
Source File: JFXListBoxSelectCellFactory.java From tuxguitar with GNU Lesser General Public License v2.1 | 6 votes |
@Override public ListCell<JFXListBoxSelectItem<T>> call(ListView<JFXListBoxSelectItem<T>> listView) { return new ListCell<JFXListBoxSelectItem<T>>() { public void updateItem(JFXListBoxSelectItem<T> item, boolean empty) { super.updateItem(item, empty); this.setManaged(false); this.applyCss(); this.setGraphic(null); this.setText(empty ? null : (item != null ? item.toString() : "null")); if( item != null ) { this.setPadding(getControl().computeCellPadding()); this.setPrefWidth(getControl().computeCellWidth(item)); this.setPrefHeight(getControl().computeCellHeight(item)); } } }; }
Example #9
Source File: ListCellTextFieldTest.java From oim-fx with MIT License | 6 votes |
@Override public void start(Stage primaryStage) throws Exception { StackPane pane = new StackPane(); Scene scene = new Scene(pane, 300, 150); primaryStage.setScene(scene); ObservableList<String> list = FXCollections.observableArrayList( "Item 1", "Item 2", "Item 3", "Item 4"); ListView<String> lv = new ListView<>(list); lv.setCellFactory(new Callback<ListView<String>, ListCell<String>>() { @Override public ListCell<String> call(ListView<String> param) { return new XCell(); } }); pane.getChildren().add(lv); primaryStage.show(); }
Example #10
Source File: ListCellLabelTest.java From oim-fx with MIT License | 6 votes |
@Override public void start(Stage primaryStage) throws Exception { StackPane pane = new StackPane(); Scene scene = new Scene(pane, 300, 150); primaryStage.setScene(scene); ObservableList<String> list = FXCollections.observableArrayList( "Item 1", "Item 2", "Item 3", "Item 4"); ListView<String> lv = new ListView<>(list); lv.setCellFactory(new Callback<ListView<String>, ListCell<String>>() { @Override public ListCell<String> call(ListView<String> param) { return new XCell(); } }); pane.getChildren().add(lv); primaryStage.show(); }
Example #11
Source File: AutoCompletePopupSkin2.java From BlockMap with MIT License | 6 votes |
/** * @param cellFactory * Set a custom cell factory for the suggestions. */ public AutoCompletePopupSkin2(AutoCompletePopup<T> control, Callback<ListView<T>, ListCell<T>> cellFactory) { this.control = control; suggestionList = new ListView<>(control.getSuggestions()); suggestionList.getStyleClass().add(AutoCompletePopup.DEFAULT_STYLE_CLASS); suggestionList.getStylesheets().add(AutoCompletionBinding.class .getResource("autocompletion.css").toExternalForm()); //$NON-NLS-1$ /** * Here we bind the prefHeightProperty to the minimum height between the max visible rows and the current items list. We also add an * arbitrary 5 number because when we have only one item we have the vertical scrollBar showing for no reason. */ suggestionList.prefHeightProperty().bind( Bindings.min(control.visibleRowCountProperty(), Bindings.size(suggestionList.getItems())) .multiply(LIST_CELL_HEIGHT).add(18)); suggestionList.setCellFactory(cellFactory); // Allowing the user to control ListView width. suggestionList.prefWidthProperty().bind(control.prefWidthProperty()); suggestionList.maxWidthProperty().bind(control.maxWidthProperty()); suggestionList.minWidthProperty().bind(control.minWidthProperty()); registerEventListener(); }
Example #12
Source File: ListViewCellFactorySample.java From marathonv5 with Apache License 2.0 | 6 votes |
public ListViewCellFactorySample() { final ListView<Number> listView = new ListView<Number>(); listView.setItems(FXCollections.<Number>observableArrayList( 100.00, -12.34, 33.01, 71.00, 23000.00, -6.00, 0, 42223.00, -12.05, 500.00, 430000.00, 1.00, -4.00, 1922.01, -90.00, 11111.00, 3901349.00, 12.00, -1.00, -2.00, 15.00, 47.50, 12.11 )); listView.setCellFactory(new Callback<ListView<java.lang.Number>, ListCell<java.lang.Number>>() { @Override public ListCell<Number> call(ListView<java.lang.Number> list) { return new MoneyFormatCell(); } }); listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); getChildren().add(listView); }
Example #13
Source File: ActivityController.java From PeerWasp with MIT License | 6 votes |
/** * Wires the list view with the items source and configures filtering and sorting of the items. */ private void loadItems() { // filtering -- default show all FilteredList<ActivityItem> filteredItems = new FilteredList<>(activityLogger.getActivityItems(), p -> true); txtFilter.textProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { // filter on predicate filteredItems.setPredicate(new ActivityItemFilterPredicate(newValue)); } }); // sorting SortedList<ActivityItem> sortedItems = new SortedList<>(filteredItems, new ActivityItemTimeComparator()); // set item source lstActivityLog.setItems(sortedItems); lstActivityLog .setCellFactory(new Callback<ListView<ActivityItem>, ListCell<ActivityItem>>() { @Override public ListCell<ActivityItem> call(ListView<ActivityItem> param) { return new ActivityItemCell(); } }); }
Example #14
Source File: ImageManufacturePaneController.java From MyBox with Apache License 2.0 | 6 votes |
public void initScopesBox() { try { scopeSelector.setButtonCell(new ImageScopeCell()); scopeSelector.setCellFactory(new Callback<ListView<ImageScope>, ListCell<ImageScope>>() { @Override public ListCell<ImageScope> call(ListView<ImageScope> param) { return new ImageScopeCell(); } }); scopeSelector.setVisibleRowCount(15); scopeDeleteButton.disableProperty().bind( scopeSelector.getSelectionModel().selectedItemProperty().isNull() ); scopeUseButton.disableProperty().bind( scopeSelector.getSelectionModel().selectedItemProperty().isNull() ); } catch (Exception e) { logger.error(e.toString()); } }
Example #15
Source File: AlertFactory.java From DashboardFx with GNU General Public License v3.0 | 6 votes |
@Override public ListCell<AlertCell> call(ListView<T> param) { return new ListCell<AlertCell>(){ @Override protected void updateItem(AlertCell item, boolean empty) { super.updateItem(item, empty); if(item == null || empty) { setItem(null); setGraphic(null); setText(null); } else { setItem(item); // setText(item.get); System.out.println(item.getIcon()); setGraphic(item.getIcon()); } } }; }
Example #16
Source File: ListViewCellFactorySample.java From marathonv5 with Apache License 2.0 | 6 votes |
public ListViewCellFactorySample() { final ListView<Number> listView = new ListView<Number>(); listView.setItems(FXCollections.<Number>observableArrayList( 100.00, -12.34, 33.01, 71.00, 23000.00, -6.00, 0, 42223.00, -12.05, 500.00, 430000.00, 1.00, -4.00, 1922.01, -90.00, 11111.00, 3901349.00, 12.00, -1.00, -2.00, 15.00, 47.50, 12.11 )); listView.setCellFactory(new Callback<ListView<java.lang.Number>, ListCell<java.lang.Number>>() { @Override public ListCell<Number> call(ListView<java.lang.Number> list) { return new MoneyFormatCell(); } }); listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); getChildren().add(listView); }
Example #17
Source File: MarathonFileChooser.java From marathonv5 with Apache License 2.0 | 6 votes |
private void initListView() { if (!doesAllowChildren) { fillUpChildren(fileChooserInfo.getRoot()); } childrenListView.setCellFactory(new Callback<ListView<File>, ListCell<File>>() { @Override public ListCell<File> call(ListView<File> param) { return new ChildrenFileCell(); } }); childrenListView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { if (fileChooserInfo.isFileCreation()) { return; } File selectedItem = childrenListView.getSelectionModel().getSelectedItem(); if (selectedItem == null) { fileNameBox.clear(); } }); }
Example #18
Source File: JavaFXElementPropertyAccessor.java From marathonv5 with Apache License 2.0 | 6 votes |
protected int getIndexAt(ListView<?> listView, Point2D point) { if (point == null) { return listView.getSelectionModel().getSelectedIndex(); } point = listView.localToScene(point); Set<Node> lookupAll = getListCells(listView); ListCell<?> selected = null; for (Node cellNode : lookupAll) { Bounds boundsInScene = cellNode.localToScene(cellNode.getBoundsInLocal(), true); if (boundsInScene.contains(point)) { selected = (ListCell<?>) cellNode; break; } } if (selected == null) { return -1; } return selected.getIndex(); }
Example #19
Source File: CompositeLayout.java From marathonv5 with Apache License 2.0 | 6 votes |
private void initComponents() { optionBox.setItems(model); optionBox.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> { if (newValue != null) { updateTabPane(); } }); optionBox.setCellFactory(new Callback<ListView<PlugInModelInfo>, ListCell<PlugInModelInfo>>() { @Override public ListCell<PlugInModelInfo> call(ListView<PlugInModelInfo> param) { return new LauncherCell(); } }); optionTabpane.setId("CompositeTabPane"); optionTabpane.setTabClosingPolicy(TabClosingPolicy.UNAVAILABLE); optionTabpane.getStyleClass().add(TabPane.STYLE_CLASS_FLOATING); VBox.setVgrow(optionTabpane, Priority.ALWAYS); }
Example #20
Source File: GUIUtil.java From bisq with GNU Affero General Public License v3.0 | 6 votes |
@NotNull public static <T> ListCell<T> getComboBoxButtonCell(String title, ComboBox<T> comboBox, Boolean hideOriginalPrompt) { return new ListCell<>() { @Override protected void updateItem(T item, boolean empty) { super.updateItem(item, empty); // See https://github.com/jfoenixadmin/JFoenix/issues/610 if (hideOriginalPrompt) this.setVisible(item != null || !empty); if (empty || item == null) { setText(title); } else { setText(comboBox.getConverter().toString(item)); } } }; }
Example #21
Source File: JavaFXListViewItemElement.java From marathonv5 with Apache License 2.0 | 5 votes |
@Override public void click(int button, Node target, PickResult pickResult, int clickCount, double xoffset, double yoffset) { Node cell = getPseudoComponent(); target = getTextObj((ListCell<?>) cell); Point2D targetXY = node.localToScene(xoffset, yoffset); super.click(button, target, new PickResult(target, targetXY.getX(), targetXY.getY()), clickCount, xoffset, yoffset); }
Example #22
Source File: RFXListView.java From marathonv5 with Apache License 2.0 | 5 votes |
private String getListCellValue(ListView<?> listView, int index) { if (index == -1) { return null; } ListCell<?> listCell = getCellAt(listView, index); RFXComponent cellComponent = getFinder().findRCellComponent(listCell, null, recorder); return cellComponent == null ? null : cellComponent.getValue(); }
Example #23
Source File: SimpleListViewScrollSample.java From marathonv5 with Apache License 2.0 | 5 votes |
private static <T> ListCell<T> createDefaultCellImpl() { return new ListCell<T>() { @Override public void updateItem(T item, boolean empty) { super.updateItem(item, empty); if (empty) { setText(null); setGraphic(null); } else if (item instanceof Node) { setText(null); Node currentNode = getGraphic(); Node newNode = (Node) item; if (currentNode == null || !currentNode.equals(newNode)) { setGraphic(newNode); } } else { /** * This label is used if the item associated with this * cell is to be represented as a String. While we will * lazily instantiate it we never clear it, being more * afraid of object churn than a minor "leak" (which * will not become a "major" leak). */ setText(item == null ? "null" : item.toString()); setGraphic(null); } } }; }
Example #24
Source File: JFXListBoxSelect.java From tuxguitar with GNU Lesser General Public License v2.1 | 5 votes |
public JFXFontMetrics computeCellFontMetrics() { if( this.cellFontMetrics == null ) { ListCell<T> listCell = new ListCell<T>(); listCell.setManaged(false); listCell.applyCss(); this.cellFontMetrics = new JFXFontMetrics(listCell.getFont()); } return this.cellFontMetrics; }
Example #25
Source File: JavaFXListViewElementScrollTest.java From marathonv5 with Apache License 2.0 | 5 votes |
public Point2D getPoint(ListView<?> listView, int index) { Set<Node> cells = listView.lookupAll(".list-cell"); for (Node node : cells) { ListCell<?> cell = (ListCell<?>) node; if (cell.getIndex() == index) { Bounds bounds = cell.getBoundsInParent(); return cell.localToParent(bounds.getWidth() / 2, bounds.getHeight() / 2); } } return null; }
Example #26
Source File: BasicListView.java From gluon-samples with BSD 3-Clause "New" or "Revised" License | 5 votes |
public BasicListView() { // create a DataSource that loads data from a classpath resource InputDataSource dataSource = new BasicInputDataSource(Main.class.getResourceAsStream("/languages.json")); // create a Converter that converts a json array into a list InputStreamIterableInputConverter<Language> converter = new JsonIterableInputConverter<>(Language.class); // create a ListDataReader that will read the data from the DataSource and converts // it from json into a list of objects ListDataReader<Language> listDataReader = new InputStreamListDataReader<>(dataSource, converter); // retrieve a list from the DataProvider GluonObservableList<Language> programmingLanguages = DataProvider.retrieveList(listDataReader); // create a JavaFX ListView and populate it with the retrieved list ListView<Language> lvProgrammingLanguages = new ListView<>(programmingLanguages); lvProgrammingLanguages.setCellFactory(lv -> new ListCell<Language>() { @Override protected void updateItem(Language item, boolean empty) { super.updateItem(item, empty); if (!empty) { setText(item.getName() + ": " + item.getRatings() + "%"); } else { setText(null); } } }); setCenter(lvProgrammingLanguages); }
Example #27
Source File: FileListView.java From gluon-samples with BSD 3-Clause "New" or "Revised" License | 5 votes |
public FileListView() throws IOException { File languagesFile = new File(ROOT_DIR, "languages.json"); // create a FileClient to the specified file FileClient fileClient = FileClient.create(languagesFile); // create a JSON converter that converts the nodes from a JSON array into language objects InputStreamIterableInputConverter<Language> converter = new JsonIterableInputConverter<>(Language.class); // retrieve a list from a ListDataReader created from the FileClient GluonObservableList<Language> languages = DataProvider.retrieveList(fileClient.createListDataReader(converter)); // create a JavaFX ListView and populate it with the retrieved list ListView<Language> lvLanguages = new ListView<>(languages); lvLanguages.setCellFactory(lv -> new ListCell<Language>() { @Override protected void updateItem(Language item, boolean empty) { super.updateItem(item, empty); if (!empty) { setText(item.getName() + " - " + item.getRatings()); } else { setText(null); } } }); setCenter(lvLanguages); }
Example #28
Source File: JFXComboBox.java From JFoenix with Apache License 2.0 | 5 votes |
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(); } }
Example #29
Source File: CellRenderer.java From JavaFX-Chat with GNU General Public License v3.0 | 5 votes |
@Override public ListCell<User> call(ListView<User> p) { ListCell<User> cell = new ListCell<User>(){ @Override protected void updateItem(User user, boolean bln) { super.updateItem(user, bln); setGraphic(null); setText(null); if (user != null) { HBox hBox = new HBox(); Text name = new Text(user.getName()); ImageView statusImageView = new ImageView(); Image statusImage = new Image(getClass().getClassLoader().getResource("images/" + user.getStatus().toString().toLowerCase() + ".png").toString(), 16, 16,true,true); statusImageView.setImage(statusImage); ImageView pictureImageView = new ImageView(); Image image = new Image(getClass().getClassLoader().getResource("images/" + user.getPicture().toLowerCase() + ".png").toString(),50,50,true,true); pictureImageView.setImage(image); hBox.getChildren().addAll(statusImageView, pictureImageView, name); hBox.setAlignment(Pos.CENTER_LEFT); setGraphic(hBox); } } }; return cell; }
Example #30
Source File: JavaFXListViewItemElement.java From marathonv5 with Apache License 2.0 | 5 votes |
private Node getEditor() { ListCell<?> cell = (ListCell<?>) getPseudoComponent(); cell.getListView().edit(cell.getIndex()); Node cellComponent = cell.getGraphic(); cellComponent.getProperties().put("marathon.celleditor", true); cellComponent.getProperties().put("marathon.cell", cell); return cellComponent; }