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

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

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

ListView.getItems介绍

暂无

代码示例

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

public void invalidateResults(boolean error) {
  xpathResultListView.getItems().clear();
  parent.resetXPathResults();
  violationsTitledPane.setTitle("Matched nodes" + (error ? "\t(error)" : ""));
}

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

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

代码示例来源: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: 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: jfoenixadmin/JFoenix

private void updateListHeight() {
  final double height = Math.min(suggestionList.getItems().size(), getSkinnable().getCellLimit()) * suggestionList.getFixedCellSize();
  suggestionList.setPrefHeight(height + suggestionList.getFixedCellSize() / 2);
}

代码示例来源: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: 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: pmd/pmd

private void onSelectFileClicked() {
  FileChooser chooser = new FileChooser();
  chooser.setTitle("Add files to the auxilliary classpath");
  chooser.getExtensionFilters().addAll(
      new FileChooser.ExtensionFilter("Java archives", "*.jar", "*.war", "*.ear"),
      new FileChooser.ExtensionFilter("Java class files", "*.class")
  );
  List<File> files = chooser.showOpenMultipleDialog(designerRoot.getMainStage());
  fileListView.getItems().addAll(files);
}

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

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

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

onApply.accept(fileListView.getItems());
});

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

javaList.getItems().add(ITEM + i);

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

suggestionList.setFixedCellSize(control.getFixedCellSize());
control.fixedCellSizeProperty().addListener(observable -> suggestionList.setFixedCellSize(control.getFixedCellSize()));
suggestionList.getItems().addListener((InvalidationListener) observable -> {
  itemChanged = true;
  updateListHeight();

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

@Override
protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
  final int itemsCount = getSkinnable().getItems().size();
  if (getSkinnable().maxHeightProperty().isBound() || itemsCount <= 0) {
    return super.computePrefHeight(width, topInset, rightInset, bottomInset, leftInset);
  }
  final double fixedCellSize = getSkinnable().getFixedCellSize();
  double computedHeight = fixedCellSize != Region.USE_COMPUTED_SIZE ?
    fixedCellSize * itemsCount + snapVerticalInsets() : estimateHeight();
  double height = super.computePrefHeight(width, topInset, rightInset, bottomInset, leftInset);
  if (height > computedHeight) {
    height = computedHeight;
  }
  if (getSkinnable().getMaxHeight() > 0 && computedHeight > getSkinnable().getMaxHeight()) {
    return getSkinnable().getMaxHeight();
  }
  return height;
}

代码示例来源: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: jfoenixadmin/JFoenix

yearsListView.getItems().add(Integer.toString(1900 + i));

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

private void move(ListView<T> viewA, ListView<T> viewB, List<T> items) {
  for (T item : items) {
    viewA.getItems().remove(item);
    viewB.getItems().add(item);
  }
}

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

/**
 * Get the number of rows in the list.
 *
 * @param list
 * @return number of rows in list
 */
public static int numberOfRowsIn(ListView<?> list) {
  return list.getItems().size();
}

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

void selectAllValues() {
  checkListView.getItems().stream()
      .forEach(item -> item.selectedProperty().set(true));
}
void unSelectAllValues() {

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

void unSelectAllValues() {
  checkListView.getItems().stream()
      .forEach(item -> item.selectedProperty().set(false));
}
void selectValue(Object value) {

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

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

相关文章