本文整理了Java中javafx.scene.control.TreeView
类的一些代码示例,展示了TreeView
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TreeView
类的具体详情如下:
包路径:javafx.scene.control.TreeView
类名称:TreeView
暂无
代码示例来源:origin: pmd/pmd
@Override
protected void updateItem(Node item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
setGraphic(null);
return;
} else {
setText(item.toString() + (item.getImage() == null ? "" : " \"" + item.getImage() + "\""));
setContextMenu(buildContextMenu(item));
}
// Reclicking the selected node in the ast will scroll back to the node in the editor
this.addEventHandler(MouseEvent.MOUSE_CLICKED, t -> {
if (t.getButton() == MouseButton.PRIMARY
&& getTreeView().getSelectionModel().getSelectedItem().getValue() == item) {
controller.onNodeItemSelected(item);
t.consume();
}
});
}
代码示例来源:origin: pmd/pmd
@Override
protected void beforeParentInit() {
treeViewWrapper = new TreeViewWrapper<>(astTreeView);
astTreeView.setCellFactory(treeView -> new ASTTreeCell(parent));
initializeLanguageSelector(); // languageVersionProperty() must be initialized
languageVersionProperty().values()
.filterMap(Objects::nonNull, LanguageVersion::getLanguage)
.distinct()
.subscribe(this::updateSyntaxHighlighter);
languageVersionProperty().values()
.filter(Objects::nonNull)
.map(LanguageVersion::getShortName)
.map(lang -> "Source Code (" + lang + ")")
.subscribe(editorTitledPane::setTitle);
EventStreams.valuesOf(astTreeView.getSelectionModel().selectedItemProperty())
.filterMap(Objects::nonNull, TreeItem::getValue)
.subscribe(parent::onNodeItemSelected);
codeEditorArea.plainTextChanges()
.filter(t -> !t.isIdentity())
.successionEnds(AST_REFRESH_DELAY)
// Refresh the AST anytime the text, classloader, or language version changes
.or(auxclasspathClassLoader.changes())
.or(languageVersionProperty().changes())
.subscribe(tick -> {
// Discard the AST if the language version has changed
tick.ifRight(c -> astTreeView.setRoot(null));
Platform.runLater(parent::refreshAST);
});
codeEditorArea.setParagraphGraphicFactory(lineNumberFactory());
}
代码示例来源:origin: speedment/speedment
private void populateTree(ProjectProperty project) {
requireNonNull(project);
final TreeItem<DocumentProperty> root = branch(project);
hierarchy.setRoot(root);
hierarchy.getSelectionModel().select(root);
}
代码示例来源:origin: speedment/speedment
private void prepareTree(ProjectProperty project) {
requireNonNull(project);
events.notify(new ProjectLoaded(project));
Bindings.bindContent(ui.getSelectedTreeItems(), hierarchy.getSelectionModel().getSelectedItems());
hierarchy.setCellFactory(view -> new DocumentPropertyCell(projectTreeComponent));
hierarchy.getSelectionModel().setSelectionMode(SINGLE);
populateTree(project);
}
代码示例来源:origin: pmd/pmd
private void focusNodeInTreeView(Node node) {
SelectionModel<TreeItem<Node>> selectionModel = astTreeView.getSelectionModel();
// node is different from the old one
if (selectedTreeItem == null && node != null
|| selectedTreeItem != null && !Objects.equals(node, selectedTreeItem.getValue())) {
ASTTreeItem found = ((ASTTreeItem) astTreeView.getRoot()).findItem(node);
if (found != null) {
selectionModel.select(found);
}
highlightFocusNodeParents(selectedTreeItem, found);
selectedTreeItem = found;
astTreeView.getFocusModel().focus(selectionModel.getSelectedIndex());
if (!treeViewWrapper.isIndexVisible(selectionModel.getSelectedIndex())) {
astTreeView.scrollTo(selectionModel.getSelectedIndex());
}
}
}
代码示例来源:origin: at.bestsolution.efxclipse.rt/org.eclipse.fx.ui.controls
/**
* Create a new skin
*
* @param control
* the control
* @param selectedItems
* the selected items
*/
public ResourceTreeViewSkin(ResourceTreeView control,
ObservableList<ResourceItem> selectedItems) {
super(control);
this.selectedItems = selectedItems;
this.tree = new TreeView<>();
this.tree.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
this.tree.setCellFactory((v) -> new SimpleTreeCell<@NonNull ResourceItem>(
ResourceTreeViewSkin::handleDirLabel, this::handleStyleclass));
this.tree.setShowRoot(false);
this.tree.getSelectionModel().getSelectedItems()
.addListener(this::handleSelectionChange);
this.tree.setOnMouseClicked( e -> {
if( e.getClickCount() > 1 ) {
openSelectedResources();
}
});
getChildren().add(this.tree);
control.rootDirectoriesProperty().addListener(this::rebuildTable);
control.iconSizeProperty().addListener(this::rebuildTable);
rebuildTable(control.rootDirectoriesProperty());
}
代码示例来源:origin: io.github.factoryfx/javafxDataEditing
private Node createTree(){
TreeView<TreeData> tree = new TreeView<>();
tree.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
tree.setCellFactory(param -> new DataTextFieldTreeCell<>(TreeData::getData, TreeData::getDisplayText));
tree.setRoot(constructTreeFromRoot());
tree.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
if (newValue!=null && !programmaticallySelect && newValue.getValue()!=null && newValue.getValue().getData()!=null){
dataEditor.edit(newValue.getValue().getData());
tree.setRoot(treeItemRoot);
tree.getSelectionModel().clearSelection();
for (TreeItem<TreeData> item : treeViewTraverser.breadthFirst(tree.getRoot())) {
programmaticallySelect=true;
if (item.getValue().match(newValue)) {
tree.getSelectionModel().select(item);
MenuItem menuItem = new MenuItem("expand all");
menuItem.setOnAction(event -> {
for (TreeItem<TreeData> item : treeViewTraverser.breadthFirst(tree.getRoot())) {
item.setExpanded(true);
tree.setContextMenu(contextMenu);
代码示例来源:origin: org.copper-engine/copper-monitoring-client
treeView.setRoot(new TreeItem<DisplayableNode>(null));
treeView.setShowRoot(false);
treeView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TreeItem<DisplayableNode>>() {
@Override
public void changed(
treeView.setCellFactory(new Callback<TreeView<DisplayableNode>, TreeCell<DisplayableNode>>() {
@Override
public TreeCell<DisplayableNode> call(TreeView<DisplayableNode> param) {
代码示例来源:origin: at.bestsolution.eclipse/org.eclipse.fx.code.editor.fx
private TreeView<OutlineItem> createView() {
TreeView<OutlineItem> outlineView = new TreeView<>();
outlineView.setShowRoot(false);
outlineView.setCellFactory(this::createCell);
return outlineView;
}
代码示例来源:origin: com.nexitia.emaginplatform/emagin-jfxcore-engine
treeView = new TreeView<>();
final String treePaginatedDataProvider = contentConfiguration.getPropertyValue("dataLoader");
treeView.setCache(true);
treeView.setCacheHint(CacheHint.SPEED);
treeView.setCellFactory(param -> {
final EpTreeCell<OperationData> cell = new EpTreeCell<>();
cell.setPresenterId(presenter);
treeView.setRoot(dummyRoot);
treeView.setShowRoot(false);
代码示例来源:origin: pmd/pmd
/**
* Refreshes the AST and returns the new compilation unit if the parse didn't fail.
*/
public Optional<Node> refreshAST() {
String source = getText();
if (StringUtils.isBlank(source)) {
astTreeView.setRoot(null);
return Optional.empty();
}
Optional<Node> current;
try {
current = astManager.updateIfChanged(source, auxclasspathClassLoader.getValue());
} catch (ParseAbortedException e) {
astViewTitledPane.setTitle("Abstract syntax tree (error)");
return Optional.empty();
}
current.ifPresent(this::setUpToDateCompilationUnit);
return current;
}
代码示例来源:origin: com.powsybl/powsybl-gse-afs-ext-base
Button removeButton = new Button("", removeGlyph);
removeButton.getStyleClass().add("gse-toolbar-button");
removeButton.disableProperty().bind(Bindings.isEmpty(contingencyTree.getSelectionModel().getSelectedIndices()));
removeButton.setOnAction(event -> showRemoveAlert());
ToolBar toolBar = new ToolBar(saveButton, removeButton);
contingencyTree.setCellFactory(param -> new ContingencyTreeCell());
contingencyTree.setShowRoot(false);
contingencyTree.getSelectionModel().getSelectedItems().addListener((ListChangeListener<TreeItem<Object>>) c -> {
if (c.getList().size() == 1) {
TreeItem<Object> selectedTreeItem = c.getList().get(0);
Object value = selectedTreeItem.getValue();
if (value instanceof Contingency) {
contingencyTree.setContextMenu(contingencyMenu);
} else if (value instanceof ContingencyElement) {
contingencyTree.setContextMenu(contingencyElementMenu);
} else {
contingencyTree.setContextMenu(null);
contingencyTree.setContextMenu(createMultipleContingencyMenu());
contingencyTree.addEventHandler(KeyEvent.KEY_PRESSED, this::onKeyPressed);
代码示例来源:origin: sc.fiji/OMEVisual
public void fill(OMEXMLMetadata md) {
testTree.setRoot(root);
testTree.setShowRoot(false);
testTree.getSelectionModel().selectedItemProperty()
.addListener((ObservableValue obs, Object oldValue, Object newValue) -> {
TreeItem<GenericModel<?>> selectedItem = (TreeItem<GenericModel<?>>) newValue;
代码示例来源:origin: org.copper-engine/copper-monitoring-client
public void refresh(List<WorkflowVersion> newItems) {
treeView.setShowRoot(false);
TreeItem<DisplayWorkflowClassesModel> rootItem = new TreeItem<DisplayWorkflowClassesModel>();
rootItem.getChildren().addAll(groupToTreeItem(newItems));
treeView.setRoot(rootItem);
treeView.setCellFactory(new Callback<TreeView<DisplayWorkflowClassesModel>, TreeCell<DisplayWorkflowClassesModel>>() {
@Override
public TreeCell<DisplayWorkflowClassesModel> call(TreeView<DisplayWorkflowClassesModel> listView) {
return new TextFieldTreeCell<DisplayWorkflowClassesModel>(new StringConverter<DisplayWorkflowClassesModel>() {
@Override
public DisplayWorkflowClassesModel fromString(String string) {
return null;
}
@Override
public String toString(DisplayWorkflowClassesModel object) {
return object.displayName;
}
});
}
});
rootItem.setExpanded(true);
}
代码示例来源:origin: com.aquafx-project/aquafx
TreeView<String> treeView = new TreeView<String>();
treeView.setRoot(root);
treeView.setCellFactory(CheckBoxTreeCell.<String> forTreeView());
TreeView<String> treeView1 = new TreeView<String>();
treeView1.setRoot(root1);
treeView1.setCellFactory(CheckBoxTreeCell.<String> forTreeView());
代码示例来源:origin: com.aquafx-project/aquafx
childNode19, childNode20, childNode21);
final TreeView treeView = new TreeView(root);
treeView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
treeView.setShowRoot(true);
treeView.setPrefSize(width, 300);
treeView.getSelectionModel().selectRange(5, 8);
return treeView;
代码示例来源:origin: eu.agrosense.client/util-javafx
@Override
public void addNotify() {
super.addNotify();
em = ExplorerManager.find(this);
if (em != null) {
TreeItem<Node> rootItem = createFromNode(em.getRootContext());
rootItem.setExpanded(true);
final TreeView<Node> treeView = new TreeView<>(rootItem);
treeView.setEditable(true);
treeView.setShowRoot(rootVisible);
treeView.setCellFactory(
new Callback<TreeView<Node>, TreeCell<Node>>() {
@Override
public TreeCell<Node> call(final TreeView<Node> p) {
return new TextFieldTreeCellImpl();
}
});
Platform.runLater(new Runnable() {
@Override
public void run() {
StackPane root = new StackPane();
root.getChildren().add(treeView);
Scene scene = new Scene(root, 300, 250);
setScene(scene);
}
});
}
}
// for custom cell editor with edit capabilities:
代码示例来源:origin: nl.cloudfarming.client/calendar-api
setMaxWidth(LIST_VIEW_WIDTH);
treeView = new TreeView<>(rootItem);
treeView.setCellFactory(createCellFactory(contextMenu));
treeView.setShowRoot(false);
treeView.getStyleClass().add("node-list");
treeViewPane.setCenter(treeView);
代码示例来源:origin: jfoenixadmin/JFoenix
setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
setFitToHeight(true);
treeView.getSelectionModel().selectedItemProperty().addListener(observable -> {
TreeItem selectedItem = treeView.getSelectionModel().getSelectedItem();
TreeItem temp = selectedItem;
int level = treeView.getTreeItemLevel(temp) - (treeView.isShowRoot() ? 0 : 1);
if (temp != null) {
List<Node> newPath = new ArrayList<>();
while (temp != null) {
TreeItem parent = treeView.isShowRoot() ? temp : temp.getParent();
if (parent != null) {
Button button = null;
button.setOnAction(action -> treeView.scrollTo(treeView.getRow(node)));
final StackPane container = new StackPane(button);
container.setPickOnBounds(false);
代码示例来源:origin: it.unibo.alchemist/alchemist-projectview
final TreeItem<String> root = new TreeItem<>(dir.getName(), new ImageView(SVGImageUtils.getSvgImage("icon/project.svg", TREE_ICON_WIDTH, TREE_ICON_HEIGHT)));
root.setExpanded(true);
this.treeView = new TreeView<>(root);
displayProjectContent(dir, root);
this.pane.getChildren().add(this.treeView);
this.treeView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TreeItem<String>>() {
@Override
public void changed(final ObservableValue<? extends TreeItem<String>> observable,
this.treeView.setOnMouseClicked(mouseEv -> {
final File target = new File(selectedFile);
if (mouseEv.getClickCount() == 2 && target.exists() && target.isFile()) {
newFile.setOnAction(e -> loadLayout(false));
menu.getItems().addAll(newFolder, newFile);
this.treeView.setContextMenu(menu);
内容来源于网络,如有侵权,请联系作者删除!