javafx.collections.ObservableList.size()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(174)

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

ObservableList.size介绍

暂无

代码示例

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

public Node getContent() {
  return contentContainer.getChildren().size() == 2 ? contentContainer.getChildren().get(1) : null;
}

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

public void setBottomTabIndex(int i) {
  if (i >= 0 && i < bottomTabPane.getTabs().size()) {
    bottomTabPane.getSelectionModel().select(i);
  }
}

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

public void setContent(Node content) {
  if (contentContainer.getChildren().size() == 2) {
    contentContainer.getChildren().set(1, content);
  } else if (contentContainer.getChildren().size() == 1) {
    contentContainer.getChildren().add(content);
  } else {
    contentContainer.getChildren().setAll(headerSpace, content);
  }
  VBox.setVgrow(content, Priority.ALWAYS);
}

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

@Override
protected void updateChildren() {
  super.updateChildren();
  if(buttonRippler!=null)
    getChildren().add(0, buttonRippler);
  for (int i = 1; i < getChildren().size(); i++) {
    final Node child = getChildren().get(i);
    if(child instanceof Text)
      child.setMouseTransparent(true);
  }
}

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

@Override
protected void updateChildren() {
  super.updateChildren();
  if (rippler != null) {
    getChildren().add(0, rippler);
  }
  for (int i = 1; i < getChildren().size(); i++) {
    getChildren().get(i).setMouseTransparent(true);
  }
}

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

private void createChip(T item) {
  JFXChip<T> chip = null;
  try {
    if (getSkinnable().getChipFactory() != null) {
      chip = getSkinnable().getChipFactory().apply(getSkinnable(), item);
    } else {
      chip = new JFXDefaultChip<T>(getSkinnable(), item);
    }
  } catch (Exception e) {
    throw new RuntimeException("can't create chip for item '" + item +
                  "' make sure to override the string converter and return null if text input is not valid.", e);
  }
  int size = root.getChildren().size();
  root.getChildren().add(size - 1, chip);
}

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

private void removeRadio() {
  for (int i = 0; i < getChildren().size(); i++) {
    if ("radio".equals(getChildren().get(i).getStyleClass().get(0))) {
      getChildren().remove(i);
      break;
    }
  }
}

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

private void createAnimation(boolean expanded, Timeline animation) {
  final ObservableList<Node> children = getChildren();
  double duration = 160 / (double) children.size();
  // show child nodes
  if (expanded) {
    for (Node child : children) {
      child.setVisible(true);
    }
  }
  // add child nodes animation
  for (int i = 1; i < children.size(); i++) {
    Node child = children.get(i);
    Collection<KeyFrame> frames = animationsMap.get(child).apply(expanded, Duration.millis(i * duration));
    animation.getKeyFrames().addAll(frames);
  }
  // add 1st element animation
  Collection<KeyFrame> frames = animationsMap.get(children.get(0)).apply(expanded, Duration.millis(160));
  animation.getKeyFrames().addAll(frames);
  // hide child nodes to allow mouse events on the nodes behind them
  if (!expanded) {
    animation.setOnFinished((finish) -> {
      for (int i = 1; i < children.size(); i++) {
        children.get(i).setVisible(false);
      }
    });
  } else {
    animation.setOnFinished(null);
  }
}

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

/**
 * add node to list with a specified callback that is triggered after the node animation is finished.
 * Note: this method must be called instead of getChildren().add().
 *
 * @param node {@link Region} to add
 */
public void addAnimatedNode(Region node, BiFunction<Boolean, Duration, Collection<KeyFrame>> animationFramesFunction, boolean addTriggerListener) {
  // create container for the node if it's a sub nodes list
  if (node instanceof JFXNodesList) {
    StackPane container = new StackPane(node);
    container.setPickOnBounds(false);
    addAnimatedNode(container, animationFramesFunction, addTriggerListener);
    return;
  }
  // init node property and its listeners
  initChild(node, getChildren().size(), animationFramesFunction, addTriggerListener);
  // add the node
  getChildren().add(node);
}

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

void createRipple() {
  if (enabled) {
    if (!generating.getAndSet(true)) {
      // create overlay once then change its color later
      createOverlay();
      if (this.getClip() == null || (getChildren().size() == 1 && !cacheRipplerClip) || resetClip) {
        this.setClip(getMask());
      }
      this.resetClip = false;
      // create the ripple effect
      final Ripple ripple = new Ripple(generatorCenterX, generatorCenterY);
      getChildren().add(ripple);
      ripplesQueue.add(ripple);
      // animate the ripple
      overlayRect.outAnimation.stop();
      overlayRect.inAnimation.play();
      ripple.inAnimation.play();
    }
  }
}

代码示例来源: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 clearSelection(JFXListView<?> selectedList) {
  if (allowClear) {
    allowClear = false;
    if (this != selectedList) {
      this.getSelectionModel().clearSelection();
    }
    for (int i = 0; i < sublistsProperty.get().size(); i++) {
      if (sublistsProperty.get().get(i) != selectedList) {
        sublistsProperty.get().get(i).getSelectionModel().clearSelection();
      }
    }
    allowClear = true;
  }
}

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

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

public FilterableTreeItem(T value) {
  super(value);
  this.sourceList = FXCollections.observableArrayList();
  this.filteredList = new FilteredList<>(this.sourceList);
  this.filteredList.predicateProperty().bind(Bindings.createObjectBinding(() -> {
    return child -> {
      // Set the predicate of child items to force filtering
      if (child instanceof FilterableTreeItem) {
        FilterableTreeItem<T> filterableChild = (FilterableTreeItem<T>) child;
        filterableChild.setPredicate(this.predicate.get());
      }
      // If there is no predicate, keep this tree item
      if (this.predicate.get() == null)
        return true;
      // If there are children, keep this tree item
      if (child.getChildren().size() > 0)
        return true;
      // Otherwise ask the TreeItemPredicate
      return this.predicate.get().test(this, child.getValue());
    };
  }, this.predicate));
  setHiddenFieldChildren(this.filteredList);
}

代码示例来源: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());
}

相关文章