@FXML private ListView listView; @FXML public void handleMouseClick(MouseEvent arg0) { System.out.println("clicked on " + listView.getSelectionModel().getSelectedItem()); }
final ListView lv = new ListView(FXCollections.observableList(Arrays.asList("one", "2", "3"))); lv.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { System.out.println("clicked on " + lv.getSelectionModel().getSelectedItem()); } });
private void selectItem() { T item = suggestionList.getSelectionModel().getSelectedItem(); if (item == null) { try { suggestionList.getSelectionModel().select(0); item = suggestionList.getSelectionModel().getSelectedItem(); } catch (Exception e) { } } if (item != null) { control.getSelectionHandler().handle(new JFXAutoCompleteEvent<T>(JFXAutoCompleteEvent.SELECTION, item)); } }
private void onRemoveFileClicked() { File f = fileListView.getSelectionModel().getSelectedItem(); fileListView.getItems().remove(f); }
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); }
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; }
@Override protected void layoutChildren() { super.layoutChildren(); if (itemChanged) { if (suggestionList.getItems().size() > 0) { suggestionList.getSelectionModel().select(0); suggestionList.scrollTo(0); } itemChanged = false; } } };
private Button removeButton(final ListView<String> listView) { final Button button = new Button("Remove Selected", FontAwesome.TIMES.view()); button.setOnAction(e -> { final int selectedIdx = listView.getSelectionModel().getSelectedIndex(); if (selectedIdx != -1 && listView.getItems().size() > 1) { final int newSelectedIdx = (selectedIdx == listView.getItems().size() - 1) ? selectedIdx - 1 : selectedIdx; listView.getItems().remove(selectedIdx); listView.getSelectionModel().select(newSelectedIdx); } }); return button; }
@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()); }
@Override protected void beforeParentInit() { xpathExpressionArea.setSyntaxHighlighter(new XPathSyntaxHighlighter()); initGenerateXPathFromStackTrace(); initialiseVersionSelection(); expressionTitledPane.titleProperty().bind(xpathVersionUIProperty.map(v -> "XPath Expression (" + v + ")")); xpathResultListView.setCellFactory(v -> new XpathViolationListCell()); exportXpathToRuleButton.setOnAction(e -> showExportXPathToRuleWizard()); EventStreams.valuesOf(xpathResultListView.getSelectionModel().selectedItemProperty()) .conditionOn(xpathResultListView.focusedProperty()) .filter(Objects::nonNull) .map(TextAwareNodeWrapper::getNode) .subscribe(parent::onNodeItemSelected); xpathExpressionArea.richChanges() .filter(t -> !t.isIdentity()) .successionEnds(XPATH_REFRESH_DELAY) // Reevaluate XPath anytime the expression or the XPath version changes .or(xpathVersionProperty().changes()) .subscribe(tick -> parent.refreshXPathResults()); }
lstProjectProblems.getSelectionModel().selectedItemProperty().addListener((ov, oldValue, newValue) -> { txtDescription.getChildren().clear(); if( newValue != null ) {
static boolean hasSelectedRow(ListView<?> list, Object rowValue) { return list.getSelectionModel().getSelectedItems() .stream() .anyMatch(rowData -> rowValue.equals(rowData) || rowValue.equals(rowData.toString())); }
private void move(ListView<T> viewA, ListView<T> viewB) { List<T> selectedItems = new ArrayList<>(viewA.getSelectionModel() .getSelectedItems()); move(viewA, viewB, selectedItems); }
private ListView<T> createListView() { ListView<T> view = new ListView<>(); view.getSelectionModel().setSelectionMode(MULTIPLE); return view; } }
@Override public void run() { listView.scrollTo(selection); listView.getSelectionModel().select(selection); } });
@Override protected void setStepEvents() { this.setNextButtonAction(event -> { MenuItem menuItem = new MenuItem(listViewWidget.getSelectionModel().getSelectedItem(), listViewWidget.getSelectionModel().getSelectedIndex()); messageWaitingForResponse.send(menuItem); }); }
private void bindMoveButtonsToSelectionModel() { moveToTarget.disableProperty().bind( Bindings.isEmpty(getSourceListView().getSelectionModel() .getSelectedItems())); moveToSource.disableProperty().bind( Bindings.isEmpty(getTargetListView().getSelectionModel() .getSelectedItems())); }
private void moveToTargetAll() { move(getSourceListView(), getTargetListView(), new ArrayList<>( getSourceListView().getItems())); getSourceListView().getSelectionModel().clearSelection(); }
private void moveToSourceAll() { move(getTargetListView(), getSourceListView(), new ArrayList<>( getTargetListView().getItems())); getTargetListView().getSelectionModel().clearSelection(); }
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())); }