javafx.scene.control.ListView.getSelectionModel()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(234)

本文整理了Java中javafx.scene.control.ListView.getSelectionModel()方法的一些代码示例,展示了ListView.getSelectionModel()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ListView.getSelectionModel()方法的具体详情如下:
包路径:javafx.scene.control.ListView
类名称:ListView
方法名:getSelectionModel

ListView.getSelectionModel介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

@FXML
private ListView listView;

@FXML public void handleMouseClick(MouseEvent arg0) {
  System.out.println("clicked on " + listView.getSelectionModel().getSelectedItem());
}

代码示例来源:origin: stackoverflow.com

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());
   }
 });

代码示例来源:origin: jfoenixadmin/JFoenix

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));
  }
}

代码示例来源:origin: pmd/pmd

private void onRemoveFileClicked() {
  File f = fileListView.getSelectionModel().getSelectedItem();
  fileListView.getItems().remove(f);
}

代码示例来源:origin: pmd/pmd

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);
}

代码示例来源:origin: speedment/speedment

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;
}

代码示例来源:origin: jfoenixadmin/JFoenix

@Override
  protected void layoutChildren() {
    super.layoutChildren();
    if (itemChanged) {
      if (suggestionList.getItems().size() > 0) {
        suggestionList.getSelectionModel().select(0);
        suggestionList.scrollTo(0);
      }
      itemChanged = false;
    }
  }
};

代码示例来源:origin: speedment/speedment

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;
}

代码示例来源:origin: pmd/pmd

@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());
}

代码示例来源:origin: pmd/pmd

@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());
}

代码示例来源:origin: speedment/speedment

lstProjectProblems.getSelectionModel().selectedItemProperty().addListener((ov, oldValue, newValue) -> {
  txtDescription.getChildren().clear();
  if( newValue != null ) {

代码示例来源:origin: org.testfx/testfx-legacy

static boolean hasSelectedRow(ListView<?> list, Object rowValue) {
  return list.getSelectionModel().getSelectedItems()
      .stream()
      .anyMatch(rowData -> rowValue.equals(rowData) || rowValue.equals(rowData.toString()));
}

代码示例来源:origin: org.controlsfx/controlsfx

private void move(ListView<T> viewA, ListView<T> viewB) {
  List<T> selectedItems = new ArrayList<>(viewA.getSelectionModel()
      .getSelectedItems());
  move(viewA, viewB, selectedItems);
}

代码示例来源:origin: org.controlsfx/controlsfx

private ListView<T> createListView() {
    ListView<T> view = new ListView<>();
    view.getSelectionModel().setSelectionMode(MULTIPLE);
    return view;
  }
}

代码示例来源:origin: org.controlsfx/controlsfx

@Override public void run() {
    listView.scrollTo(selection);
    listView.getSelectionModel().select(selection);
  }
});

代码示例来源:origin: PhoenicisOrg/phoenicis

@Override
protected void setStepEvents() {
  this.setNextButtonAction(event -> {
    MenuItem menuItem = new MenuItem(listViewWidget.getSelectionModel().getSelectedItem(),
        listViewWidget.getSelectionModel().getSelectedIndex());
    messageWaitingForResponse.send(menuItem);
  });
}

代码示例来源:origin: org.controlsfx/controlsfx

private void bindMoveButtonsToSelectionModel() {
  moveToTarget.disableProperty().bind(
      Bindings.isEmpty(getSourceListView().getSelectionModel()
          .getSelectedItems()));
  moveToSource.disableProperty().bind(
      Bindings.isEmpty(getTargetListView().getSelectionModel()
          .getSelectedItems()));
}

代码示例来源:origin: org.controlsfx/controlsfx

private void moveToTargetAll() {
  move(getSourceListView(), getTargetListView(), new ArrayList<>(
      getSourceListView().getItems()));
  getSourceListView().getSelectionModel().clearSelection();
}

代码示例来源:origin: org.controlsfx/controlsfx

private void moveToSourceAll() {
  move(getTargetListView(), getSourceListView(), new ArrayList<>(
      getTargetListView().getItems()));
  getTargetListView().getSelectionModel().clearSelection();
}

代码示例来源:origin: com.intuit.karate/karate-core

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()));        
}

相关文章