private void onRemoveFileClicked() { File f = fileListView.getSelectionModel().getSelectedItem(); fileListView.getItems().remove(f); }
suggestionList.setFixedCellSize(control.getFixedCellSize()); control.fixedCellSizeProperty().addListener(observable -> suggestionList.setFixedCellSize(control.getFixedCellSize())); suggestionList.getItems().addListener((InvalidationListener) observable -> { itemChanged = true; updateListHeight(); }); suggestionList.getStyleClass().add("autocomplete-list"); control.suggestionsCellFactoryProperty().addListener((o, oldVal, newVal) -> { if (newVal != null) { suggestionList.setCellFactory(newVal); suggestionList.setCellFactory(control.getSuggestionsCellFactory()); suggestionList.prefWidthProperty().bind(control.prefWidthProperty()); suggestionList.maxWidthProperty().bind(control.maxWidthProperty()); suggestionList.minWidthProperty().bind(control.minWidthProperty()); registerEventListener();
@Override protected void layoutChildren() { super.layoutChildren(); if (itemChanged) { if (suggestionList.getItems().size() > 0) { suggestionList.getSelectionModel().select(0); suggestionList.scrollTo(0); } itemChanged = false; } } };
private void updateListHeight() { final double height = Math.min(suggestionList.getItems().size(), getSkinnable().getCellLimit()) * suggestionList.getFixedCellSize(); suggestionList.setPrefHeight(height + suggestionList.getFixedCellSize() / 2); }
public void refresh() { // unless we do ALL of this - the custom cell rendering has problems in javafx // and starts duplicating the last row for some reason, spent a lot of time on this :( listView = new ListView(); listView.setItems(FXCollections.observableArrayList(units)); listView.setCellFactory(lv -> new FeatureOutlineCell()); scrollPane.setContent(listView); listView.getSelectionModel() .selectedIndexProperty() .addListener((o, prev, value) -> session.setSelectedScenario(value.intValue())); }
final ListView<DetailsListElement<E>> container = new ListView<>(); container.getStyleClass().addAll("listWidget", "detailsListWidget"); container.setPrefWidth(0); container.setPrefHeight(0); container.setCellFactory(param -> { final ListCell<DetailsListElement<E>> listCell = new ListCell<DetailsListElement<E>>() { @Override }); Bindings.bindContent(container.getItems(), mappedElements);
list.setCellFactory(param -> { return new ListCell<SaveFile>() { @Override }); list.setItems(listener.getSaveLoadManager().saveFiles()); list.prefHeightProperty().bind(Bindings.size(list.getItems()).multiply(FONT_SIZE)); btnLoad.disableProperty().bind(list.getSelectionModel().selectedItemProperty().isNull()); SaveFile saveFile = list.getSelectionModel().getSelectedItem(); btnDelete.disableProperty().bind(list.getSelectionModel().selectedItemProperty().isNull()); SaveFile saveFile = list.getSelectionModel().getSelectedItem();
this.listView = new ListView<>(); this.listView.getStyleClass().add("efx-perspective-list"); //$NON-NLS-1$ this.listView.setCellFactory(PerspectiveCell::new); List<MPerspective> list = this.modelService.findElements(this.window, null, MPerspective.class, null); this.listView.setItems( FXCollections.observableArrayList( list.stream().filter( e -> e.isToBeRendered()).collect(Collectors.toList())) ); this.listView.getSelectionModel().selectedItemProperty().addListener((o, ol, ne) -> { if (this.selectionConsumer != null) { this.selectionConsumer.accept(ne); this.listView.addEventHandler(MouseEvent.MOUSE_CLICKED, e -> { if (e.getClickCount() > 1) { handleOpenRequest(); this.listView.addEventHandler(KeyEvent.KEY_PRESSED, e -> { if (e.getCode() == KeyCode.ENTER) { handleOpenRequest(); this.listView.getSelectionModel().select(this.currentPerspective);
@Override public void initialize(URL location, ResourceBundle resources) { BooleanBinding noSelection = fileListView.getSelectionModel().selectedItemProperty().isNull(); removeFileButton.disableProperty().bind(noSelection); moveItemUpButton.disableProperty().bind(noSelection.or(fileListView.getSelectionModel().selectedIndexProperty().isEqualTo(0))); // we can't just map the val because we need an ObservableNumberValue IntegerBinding lastIndexBinding = Bindings.createIntegerBinding(() -> fileListView.getItems().size() - 1, Val.wrap(fileListView.itemsProperty()).flatMap(LiveList::sizeOf)); moveItemDownButton.disableProperty().bind(noSelection.or(fileListView.getSelectionModel().selectedIndexProperty().isEqualTo(lastIndexBinding))); fileListView.setCellFactory(DesignerUtil.simpleListCellFactory(File::getName, File::getAbsolutePath)); selectFilesButton.setOnAction(e -> onSelectFileClicked()); removeFileButton.setOnAction(e -> onRemoveFileClicked()); moveItemUpButton.setOnAction(e -> moveUp()); moveItemDownButton.setOnAction(e -> moveDown()); }
private void moveItem(int direction) { // Checking selected item if (fileListView.getSelectionModel().getSelectedItem() == null) { return; } // Calculate new index using move direction int newIndex = fileListView.getSelectionModel().getSelectedIndex() + direction; if (newIndex < 0 || newIndex >= fileListView.getItems().size()) { return; } File selected = fileListView.getSelectionModel().getSelectedItem(); // Removing removable element fileListView.getItems().remove(selected); // Insert it in new position fileListView.getItems().add(newIndex, selected); //Restore Selection fileListView.scrollTo(newIndex); fileListView.getSelectionModel().select(newIndex); }
public AutoCompletePopupSkin(AutoCompletePopup<T> control){ 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(TextFieldListCell.forListView(control.getConverter())); //Allowing the user to control ListView width. suggestionList.prefWidthProperty().bind(control.prefWidthProperty()); suggestionList.maxWidthProperty().bind(control.maxWidthProperty()); suggestionList.minWidthProperty().bind(control.minWidthProperty()); registerEventListener(); }
final ListView<String> v = new ListView<String>(); v.setItems(FXCollections.observableArrayList(Font.getFamilies())); v.getSelectionModel().select(this.font.get().getFamily()); v.scrollTo(this.font.get().getFamily()); v.setPrefHeight(250); ListView<FontPosture> v = new ListView<>(); v.setItems(FXCollections.observableArrayList(FontPosture .values())); v.getSelectionModel().select(posture); v.scrollTo(posture); v.setPrefWidth(120); v.setPrefHeight(250); ListView<FontWeight> v = new ListView<>(); v.setItems(FXCollections.observableArrayList(FontWeight .values())); container.getChildren().add(v); v.setPrefHeight(250); v.setPrefWidth(120); ListView<Double> v = new ListView<Double>(); ObservableList<Double> sizes = FXCollections .observableArrayList(Double.valueOf(8d), Double.valueOf(9d), Double.valueOf(10d), Double.valueOf(11d), Double.valueOf(12d), Double.valueOf(14d), Double.valueOf(16d), v.setItems(sizes); v.getSelectionModel().select(Double.valueOf(this.font.get().getSize())); v.setPrefWidth(80);
@FXML private ListView listView; @FXML public void handleMouseClick(MouseEvent arg0) { System.out.println("clicked on " + listView.getSelectionModel().getSelectedItem()); }
private Button addButton(final ListView<String> listView) { final Button button = new Button("Add Item", FontAwesome.PLUS.view()); button.setOnAction(e -> { final int newIndex = listView.getItems().size(); final Set<String> set = new HashSet<>(strings); final AtomicInteger i = new AtomicInteger(0); while (!set.add(DEFAULT_FIELD + i.incrementAndGet())) {} listView.getItems().add(DEFAULT_FIELD + i.get()); listView.scrollTo(newIndex); listView.getSelectionModel().select(newIndex); // There is a strange behavior in JavaFX if you try to start editing // a field on the same animation frame as another field lost focus. // Therefore, we wait one animation cycle before setting the field // into the editing state runLater(() -> listView.edit(newIndex)); }); return button; }
static ListView<String> createListView(int numOfItems, boolean multipleSelection, boolean disable, boolean horiz) { ListView<String> listView = new ListView<String>(); if (horiz) listView.setOrientation(Orientation.HORIZONTAL); listView.setPrefHeight((24*7)+4); listView.setPrefWidth(horiz ? 200 : 140); listView.getItems().addAll(sampleItems(numOfItems)); listView.setDisable(disable); if (multipleSelection) { listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); listView.getSelectionModel().selectRange(1, 5); } else { listView.getSelectionModel().select(1); } return listView; }
this.repositoryLayout.setSpacing(5); this.repositoryListView = new ListView<>(repositories); this.repositoryListView.setPrefHeight(0); this.repositoryListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); this.repositoryListView.setEditable(true); this.repositoryListView.setCellFactory(param -> new DragableRepositoryListCell((repositoryUrl, toIndex) -> { this.repositoryManager.moveRepository(repositoryUrl, toIndex.intValue()); this.removeButton.setText(tr("Remove")); this.removeButton.setOnAction((ActionEvent event) -> { RepositoryLocation<? extends Repository>[] toRemove = repositoryListView.getSelectionModel() .getSelectedItems().toArray(new RepositoryLocation[0]);
Bindings.bindContent(issues, issueComponent.getIssues()); lstProjectProblems.setItems(issues); lstProjectProblems.setCellFactory((ListView<Issue> param) -> new ListCell<Issue>() { @Override protected void updateItem(Issue item, boolean empty) { lstProjectProblems.getSelectionModel().selectedItemProperty().addListener((ov, oldValue, newValue) -> { txtDescription.getChildren().clear(); if( newValue != null ) {
/** * Setup a list * * @param listView * the list view * @param items * the items * @param labelPropertyExtractor * the extractor * @return the list view * @since 2.3.0 */ public static <T> ListView<T> setupList(ListView<T> listView, ObservableList<T> items, Function<T, StringExpression> labelPropertyExtractor) { listView.setCellFactory(v -> new ListCell<T>() { @Override protected void updateItem(T item, boolean empty) { super.updateItem(item, empty); textProperty().unbind(); if (item != null && !empty) { textProperty().bind(labelPropertyExtractor.apply(item)); } else { setText(null); } } }); listView.setItems(items); return listView; } }
public void invalidateResults(boolean error) { xpathResultListView.getItems().clear(); parent.resetXPathResults(); violationsTitledPane.setTitle("Matched nodes" + (error ? "\t(error)" : "")); }