本文整理汇总了Java中javafx.scene.control.TreeView类的典型用法代码示例。如果您正苦于以下问题:Java TreeView类的具体用法?Java TreeView怎么用?Java TreeView使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TreeView类属于javafx.scene.control包,在下文中一共展示了TreeView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTreeView
import javafx.scene.control.TreeView; //导入依赖的package包/类
public TreeView<Concept> getTreeView() {
if (treeView == null) {
TreeCellFactory cellFactory = new TreeCellFactory(conceptService);
treeView = new TreeView<>();
treeView.getStyleClass().add("concepttree-treeview");
treeView.setEditable(false);
treeView.setCellFactory(tv -> cellFactory.build());
treeView.setContextMenu(getContextMenu());
conceptService.findRoot()
.thenApply(root -> {
Platform.runLater(() -> {
TreeItem<Concept> rootItem = buildTreeItem(root, null);
treeView.setRoot(rootItem);
});
return null;
});
}
return treeView;
}
示例2: setNowObject
import javafx.scene.control.TreeView; //导入依赖的package包/类
public static synchronized void setNowObject(Object obj, Field f){
if (!start)
start();
while (!start)
Animation.sleepSeconds(1);
PlatformImpl.startup(() -> {});
Platform.runLater(() -> {
TreeItem<String> rootItem = new TreeItem<String>((f == null ? "" : f.getName()) + obj.getClass().getName() + " : " + obj);
TreeView<String> tree = new TreeView<String> (rootItem);
rootItem.setExpanded(true);
try {
addChildren(obj, obj, f, null, rootItem);
} catch(Exception e){e.printStackTrace();}
StackPane root = new StackPane();
root.getChildren().add(tree);
stage.setScene(new Scene(root));
});
}
示例3: setTreeCellFactory
import javafx.scene.control.TreeView; //导入依赖的package包/类
/**
* Customizing treeView
*
* @param tree treeView
*/
private void setTreeCellFactory(TreeView<SimpleTreeElement> tree) {
tree.setCellFactory(param -> new TreeCell<SimpleTreeElement>() {
@Override
public void updateItem(SimpleTreeElement item, boolean empty) {
super.updateItem(item, empty);
//setDisclosureNode(null);
if (empty) {
setText("");
setGraphic(null);
} else {
setText(item.getName());
}
}
});
tree.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
System.out.println(newValue.getValue());
}
});
}
示例4: setAction
import javafx.scene.control.TreeView; //导入依赖的package包/类
/**
* 点击处理方法.
*
* @param treeView treeView
*/
@Override
protected void setAction(TreeView treeView) {
super.setOnAction(
(event) -> {
TreeItem<Label> item = (TreeItem) treeView.getSelectionModel().getSelectedItem();
String flag = item.getValue().getAccessibleHelp();
if ("link".equals(flag)) {
String poolId = item.getValue().getAccessibleText();
ConnectPanel connectPanel = new ConnectPanel();
connectPanel.isNewLink(false);
connectPanel.showConnectPanel(poolId);
}
}
);
}
示例5: TreeViewSample
import javafx.scene.control.TreeView; //导入依赖的package包/类
public TreeViewSample() {
final TreeItem<String> treeRoot = new TreeItem<String>("Root node");
treeRoot.getChildren().addAll(Arrays.asList(
new TreeItem<String>("Child Node 1"),
new TreeItem<String>("Child Node 2"),
new TreeItem<String>("Child Node 3")));
treeRoot.getChildren().get(2).getChildren().addAll(Arrays.asList(
new TreeItem<String>("Child Node 4"),
new TreeItem<String>("Child Node 5"),
new TreeItem<String>("Child Node 6"),
new TreeItem<String>("Child Node 7"),
new TreeItem<String>("Child Node 8"),
new TreeItem<String>("Child Node 9"),
new TreeItem<String>("Child Node 10"),
new TreeItem<String>("Child Node 11"),
new TreeItem<String>("Child Node 12")));
final TreeView treeView = new TreeView();
treeView.setShowRoot(true);
treeView.setRoot(treeRoot);
treeRoot.setExpanded(true);
getChildren().add(treeView);
}
示例6: initTreeView
import javafx.scene.control.TreeView; //导入依赖的package包/类
private void initTreeView() {
parentTreeView.setCellFactory(new Callback<TreeView<File>, TreeCell<File>>() {
@Override public TreeCell<File> call(TreeView<File> param) {
return new ParentFileCell();
}
});
parentTreeView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newVlaue) -> {
TreeItem<File> selectedItem = parentTreeView.getSelectionModel().getSelectedItem();
if (selectedItem != null) {
newFolderButton.setDisable(false);
fileNameBox.setEditable(true);
File selectedFile = selectedItem.getValue();
fillUpChildren(selectedFile);
} else {
fileNameBox.setEditable(false);
newFolderButton.setDisable(true);
childrenListView.getItems().clear();
}
});
File root = fileChooserInfo.getRoot();
TreeItem<File> rootItem = new TreeItem<>(root);
parentTreeView.setRoot(rootItem);
rootItem.setExpanded(true);
parentTreeView.getSelectionModel().select(0);
populateChildren(root, rootItem);
}
示例7: createTree
import javafx.scene.control.TreeView; //导入依赖的package包/类
private Node createTree() {
VBox treeContentBox = new VBox();
tree.setRoot(functionInfo.getRoot(true));
tree.setShowRoot(false);
tree.getSelectionModel().selectedItemProperty().addListener(new TreeViewSelectionChangeListener());
tree.setCellFactory(new Callback<TreeView<Object>, TreeCell<Object>>() {
@Override public TreeCell<Object> call(TreeView<Object> param) {
return new FunctionTreeCell();
}
});
filterByName.setOnAction((e) -> {
tree.setRoot(functionInfo.refreshNode(filterByName.isSelected()));
expandAll();
});
filterByName.setSelected(true);
expandAll();
treeContentBox.getChildren().addAll(topButtonBar, tree, filterByName);
VBox.setVgrow(tree, Priority.ALWAYS);
return treeContentBox;
}
示例8: getRowAt
import javafx.scene.control.TreeView; //导入依赖的package包/类
public int getRowAt(TreeView<?> treeView, Point2D point) {
if (point == null) {
return treeView.getSelectionModel().getSelectedIndex();
}
point = treeView.localToScene(point);
int itemCount = treeView.getExpandedItemCount();
@SuppressWarnings("rawtypes")
List<TreeCell> cells = new ArrayList<>();
for (int i = 0; i < itemCount; i++) {
cells.add(getCellAt(treeView, i));
}
TreeCell<?> selected = null;
for (Node cellNode : cells) {
Bounds boundsInScene = cellNode.localToScene(cellNode.getBoundsInLocal(), true);
if (boundsInScene.contains(point)) {
selected = (TreeCell<?>) cellNode;
break;
}
}
if (selected == null) {
return -1;
}
return selected.getIndex();
}
示例9: getByPseudoElement
import javafx.scene.control.TreeView; //导入依赖的package包/类
@Override public List<IJavaFXElement> getByPseudoElement(String selector, Object[] params) {
if (selector.equals("select-by-properties")) {
return findNodeByProperties(new JSONObject((String) params[0]));
} else if (selector.equals("root")) {
return Arrays.asList(new JavaFXTreeViewNodeElement(this, 0));
} else if (selector.equals("nth-node")) {
return Arrays.asList(new JavaFXTreeViewNodeElement(this, ((Integer) params[0]).intValue() - 1));
} else if (selector.equals("all-nodes")) {
TreeView<?> treeView = (TreeView<?>) getComponent();
ArrayList<IJavaFXElement> r = new ArrayList<>();
int nrows = treeView.getExpandedItemCount();
for (int i = 0; i < nrows; i++) {
r.add(new JavaFXTreeViewNodeElement(this, i));
}
return r;
}
return super.getByPseudoElement(selector, params);
}
示例10: setSelectionPath
import javafx.scene.control.TreeView; //导入依赖的package包/类
@SuppressWarnings("unchecked") private boolean setSelectionPath(String value) {
TreeView<?> treeView = (TreeView<?>) getComponent();
JSONArray pathElements = new JSONArray(value);
List<TreeItem<?>> paths = new ArrayList<>();
for (int i = 0; i < pathElements.length(); i++) {
paths.add(getPath(treeView, pathElements.getString(i)));
}
treeView.getSelectionModel().clearSelection();
for (@SuppressWarnings("rawtypes")
TreeItem treeItem : paths) {
if (getVisibleCellAt(treeView, treeItem) == null) {
treeView.scrollTo(treeView.getRow(treeItem));
}
treeView.getSelectionModel().select(treeItem);
}
return true;
}
示例11: selectTreeItemCheckBoxSelectedSelected
import javafx.scene.control.TreeView; //导入依赖的package包/类
@Test public void selectTreeItemCheckBoxSelectedSelected() {
TreeView<?> treeViewNode = (TreeView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-view");
CheckBoxTreeItem<?> treeItem = (CheckBoxTreeItem<?>) treeViewNode.getTreeItem(2);
treeItem.setSelected(true);
JSONObject o = new JSONObject();
o.put("select", "/Root node/Child Node 2");
IJavaFXElement item = treeView.findElementByCssSelector(".::select-by-properties('" + o.toString() + "')");
IJavaFXElement cb = item.findElementByCssSelector(".::editor");
cb.marathon_select("Child Node 2:checked");
new Wait("Wait for tree item check box to be selected") {
@Override public boolean until() {
String selected = cb.getAttribute("selected");
return selected.equals("true");
}
};
}
示例12: selectTreeItemCheckBoxSelectedNotSelected
import javafx.scene.control.TreeView; //导入依赖的package包/类
@Test public void selectTreeItemCheckBoxSelectedNotSelected() {
TreeView<?> treeViewNode = (TreeView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-view");
CheckBoxTreeItem<?> treeItem = (CheckBoxTreeItem<?>) treeViewNode.getTreeItem(2);
treeItem.setSelected(true);
JSONObject o = new JSONObject();
o.put("select", "/Root node/Child Node 2");
IJavaFXElement item = treeView.findElementByCssSelector(".::select-by-properties('" + o.toString() + "')");
IJavaFXElement cb = item.findElementByCssSelector(".::editor");
cb.marathon_select("Child Node 2:unchecked");
new Wait("Wait for tree item check box to be deselected") {
@Override public boolean until() {
String selected = cb.getAttribute("selected");
return selected.equals("false");
}
};
}
示例13: TextFieldTreeViewSample
import javafx.scene.control.TreeView; //导入依赖的package包/类
public TextFieldTreeViewSample() {
final TreeItem<String> treeRoot = new TreeItem<String>("Root node");
treeRoot.getChildren().addAll(Arrays.asList(new TreeItem<String>("Child Node 1"), new TreeItem<String>("Child Node 2"),
new TreeItem<String>("Child Node 3")));
treeRoot.getChildren().get(2).getChildren().addAll(Arrays.asList(new TreeItem<String>("Child Node 4"),
new TreeItem<String>("Child Node 5"), new TreeItem<String>("Child Node 6"), new TreeItem<String>("Child Node 7"),
new TreeItem<String>("Child Node 8"), new TreeItem<String>("Child Node 9"), new TreeItem<String>("Child Node 10"),
new TreeItem<String>("Child Node 11"), new TreeItem<String>("Child Node 12")));
final TreeView treeView = new TreeView();
treeView.setShowRoot(true);
treeView.setRoot(treeRoot);
treeRoot.setExpanded(true);
treeView.setEditable(true);
treeView.setCellFactory(TextFieldTreeCell.forTreeView());
getChildren().add(treeView);
}
示例14: ChoiceBoxTreeViewSample
import javafx.scene.control.TreeView; //导入依赖的package包/类
public ChoiceBoxTreeViewSample() {
final TreeItem<String> treeRoot = new TreeItem<String>("Root node");
treeRoot.getChildren().addAll(Arrays.asList(new TreeItem<String>("Option 1"), new TreeItem<String>("Option 2"),
new TreeItem<String>("Option 3")));
treeRoot.getChildren().get(2).getChildren().addAll(Arrays.asList(new TreeItem<String>("Option 4"),
new TreeItem<String>("Option 5"), new TreeItem<String>("Option 6")));
final TreeView treeView = new TreeView();
treeView.setShowRoot(true);
treeView.setRoot(treeRoot);
treeRoot.setExpanded(true);
treeView.setEditable(true);
treeView.setCellFactory(ChoiceBoxTreeCell.forTreeView(items));
getChildren().add(treeView);
}
示例15: ComboBoxTreeViewSample
import javafx.scene.control.TreeView; //导入依赖的package包/类
public ComboBoxTreeViewSample() {
final TreeItem<String> treeRoot = new TreeItem<String>("Root node");
treeRoot.getChildren().addAll(Arrays.asList(new TreeItem<String>("Option 1"), new TreeItem<String>("Option 2"),
new TreeItem<String>("Option 3")));
treeRoot.getChildren().get(2).getChildren().addAll(Arrays.asList(new TreeItem<String>("Option 4"),
new TreeItem<String>("Option 5"), new TreeItem<String>("Option 6")));
final TreeView treeView = new TreeView();
treeView.setShowRoot(true);
treeView.setRoot(treeRoot);
treeRoot.setExpanded(true);
treeView.setEditable(true);
treeView.setCellFactory(ComboBoxTreeCell.forTreeView(items));
getChildren().add(treeView);
}