本文整理汇总了Java中javafx.scene.control.TreeView.setRoot方法的典型用法代码示例。如果您正苦于以下问题:Java TreeView.setRoot方法的具体用法?Java TreeView.setRoot怎么用?Java TreeView.setRoot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.control.TreeView
的用法示例。
在下文中一共展示了TreeView.setRoot方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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);
}
示例4: 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);
}
示例5: CheckBoxTreeViewSample
import javafx.scene.control.TreeView; //导入方法依赖的package包/类
public CheckBoxTreeViewSample() {
final CheckBoxTreeItem<String> treeRoot = new CheckBoxTreeItem<String>("Root node");
treeRoot.getChildren().addAll(Arrays.asList(new CheckBoxTreeItem<String>("Child Node 1"),
new CheckBoxTreeItem<String>("Child Node 2"), new CheckBoxTreeItem<String>("Child Node 3")));
treeRoot.getChildren().get(2).getChildren()
.addAll(Arrays.asList(new CheckBoxTreeItem<String>("Child Node 4"), new CheckBoxTreeItem<String>("Child Node 5"),
new CheckBoxTreeItem<String>("Child Node 6"), new CheckBoxTreeItem<String>("Child Node 7"),
new TreeItem<String>("Child Node 8"), new CheckBoxTreeItem<String>("Child Node 9"),
new CheckBoxTreeItem<String>("Child Node 10"), new CheckBoxTreeItem<String>("Child Node 11"),
new CheckBoxTreeItem<String>("Child Node 12")));
final TreeView treeView = new TreeView();
treeView.setCellFactory(CheckBoxTreeCell.forTreeView());
treeView.setShowRoot(true);
treeView.setRoot(treeRoot);
treeRoot.setExpanded(true);
getChildren().add(treeView);
}
示例6: TreeViewSample1
import javafx.scene.control.TreeView; //导入方法依赖的package包/类
public TreeViewSample1() {
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"),
new TreeItem<String>("Child Node 13"), new TreeItem<String>("Child Node 14"),
new TreeItem<String>("Child Node 15"), new TreeItem<String>("Child Node 16"),
new TreeItem<String>("Child Node 17"), new TreeItem<String>("Child Node 18"),
new TreeItem<String>("Child Node 19"), new TreeItem<String>("Child Node 20"),
new TreeItem<String>("Child Node 21"), new TreeItem<String>("Child Node 22"),
new TreeItem<String>("Child Node 23"), new TreeItem<String>("Child Node 24")));
final TreeView treeView = new TreeView();
treeView.setShowRoot(true);
treeView.setRoot(treeRoot);
treeRoot.setExpanded(true);
getChildren().add(treeView);
}
示例7: CreateTreeView
import javafx.scene.control.TreeView; //导入方法依赖的package包/类
@Override
public void CreateTreeView(TreeView<String> treeview){
File[] sysroots = File.listRoots();
TreeItem<String> ThisPc = new TreeItem<>("This PC", new ImageView(new Image(ClassLoader.getSystemResourceAsStream("img/pc.png"))));
TreeItem<String>[] drives = new TreeItem[sysroots.length];
for(int i=0; i<sysroots.length;i++){
drives[i] = new TreeItem<>(sysroots[i].getAbsolutePath(), new ImageView(new Image(ClassLoader.getSystemResourceAsStream("img/thumb_Hard_Drive.png"))));
try{
drives[i].getChildren().addAll(TreeCreate(sysroots[i]));
}catch(NullPointerException x){System.out.println("Exeption x detected: "+x.fillInStackTrace()+drives[i].toString());}
finally {
ThisPc.getChildren().add(drives[i]);
}
}
treeview.setRoot(ThisPc);
}
示例8: start
import javafx.scene.control.TreeView; //导入方法依赖的package包/类
@Override
public void start(Stage stage) throws Exception {
final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.US);
final TreeView<Data> treeView = new TreeView<>();
treeView.setEditable(true);
treeView.setId(TREE_VIEW_ID);
treeView.setRoot(new TreeItem(new Data("0")));
addContent(treeView.getRoot(), 2, 4, "0");
treeView.setCellFactory(p -> new TextFieldTreeCell());
VBox vBox = new VBox();
vBox.getChildren().setAll(treeView);
Scene scene = new Scene(vBox, 800, 500);
stage.setScene(scene);
stage.show();
}
示例9: getSimple
import javafx.scene.control.TreeView; //导入方法依赖的package包/类
/**
* Generate treeView of file items
* TODO: work with VUFS items
*
* @return tree view
*/
public TreeView<SimpleTreeElement> getSimple() {
TreeView<SimpleTreeElement> tree = new TreeView<>();
TreeItem<SimpleTreeElement> root = new TreeItem<>(new SimpleTreeElement("root", 0));
TreeItem<SimpleTreeElement> outer1, outer2, inner1, inner2;
outer1 = makeBranch(new SimpleTreeElement("Folder1", 1), root);
outer2 = makeBranch(new SimpleTreeElement("Documents", 2), root);
makeBranch(new SimpleTreeElement("MyFotos", 3), outer1);
makeBranch(new SimpleTreeElement("OtherFiles", 4), outer1);
makeBranch(new SimpleTreeElement("WorkFiles", 5), root);
makeBranch(new SimpleTreeElement("Projects", 6), root);
tree.setRoot(root);
tree.setPrefWidth(200);
setTreeCellFactory(tree);
tree.setShowRoot(false);
return tree;
}
示例10: getSettingsTree
import javafx.scene.control.TreeView; //导入方法依赖的package包/类
/**
* Generate treeView of settings items
* TODO: work with Repository
*
* @return tree view
*/
public TreeView<SimpleTreeElement> getSettingsTree() {
TreeView<SimpleTreeElement> tree = new TreeView<>();
TreeItem<SimpleTreeElement> root = new TreeItem<>(new SimpleTreeElement("root", 0));
TreeItem<SimpleTreeElement> outer1, outer2, inner1, inner2;
outer1 = makeBranch(new SimpleTreeElement("Account", 1), root);
outer2 = makeBranch(new SimpleTreeElement("Clouds", 2), root);
makeBranch(new SimpleTreeElement("Dropbox", 3), outer2);
makeBranch(new SimpleTreeElement("Google Drive", 4), outer2);
makeBranch(new SimpleTreeElement("Sync", 5), root);
makeBranch(new SimpleTreeElement("Encription", 6), root);
tree.setRoot(root);
tree.setPrefWidth(200);
setTreeCellFactory(tree);
tree.setShowRoot(false);
return tree;
}
示例11: createLicenseTreePane
import javafx.scene.control.TreeView; //导入方法依赖的package包/类
/**
* Create a pane for displaying license information in a readable form.
*
* @param dirBase
* @return
*/
private Pane createLicenseTreePane(final File dirBase) {
TreeView<File> tree = new TreeView<>();
tree.setRoot(new LicenseFileTreeItem(dirBase));
tree.setShowRoot(false);
TextArea textArea = new TextArea();
textArea.setStyle("-fx-font-family: monospace");
textArea.setWrapText(true);
// Show content for selected node
tree.getSelectionModel().selectedItemProperty().addListener((v, o, n) -> {
if (n instanceof LicenseFileTreeItem)
textArea.setText(((LicenseFileTreeItem)n).getContents());
});
tree.setCellFactory(n -> new FileTreeCell());
Button btnThirdParty = new Button("Open licenses directory");
File dirLicenses = dirBase;
btnThirdParty.setOnAction(e -> {
DisplayHelpers.openFile(dirLicenses);
});
btnThirdParty.setMaxWidth(Double.MAX_VALUE);
BorderPane pane = new BorderPane();
pane.setLeft(tree);
pane.setCenter(textArea);
pane.setBottom(btnThirdParty);
return pane;
}
示例12: getView
import javafx.scene.control.TreeView; //导入方法依赖的package包/类
@Override
public Parent getView() {
Parent parent = LayoutInflater.inflate("activity_main", Parent.class);
parent.getStylesheets().add("css/main.css");
AnchorPane main_left = (AnchorPane) parent.lookup("#main_left");
StackPane main_center = (StackPane) parent.lookup("#main_center");
// left
TreeView treeView = new TreeView();
// TreeView������Ҳ�Ƿ�Node���ͣ����Բ�����SceneBuilder��ͼ��
TreeItem<String> treeItemRoot = new TreeItem<String>("�����˵�",rootIcon);
TreeItem<String> item_1 = new TreeItem<String>("���¹���",oneIcon);
TreeItem<String> item_2 = new TreeItem<String>("������",twoIcon);
TreeItem<String> item_3 = new TreeItem<String>("���ù���",eightIcon);
TreeItem<String> item_4 = new TreeItem<String>("ϵͳ����",threeIcon);
treeItemRoot.getChildren().addAll(Arrays.asList(item_1,item_2,item_3,item_4));
TreeItem<String> item_4_1 = new TreeItem<String>("����",fourIcon);
TreeItem<String> item_4_2 = new TreeItem<String>("����",fiveIcon);
TreeItem<String> item_4_3 = new TreeItem<String>("ͬ��",sixIcon);
TreeItem<String> item_4_4 = new TreeItem<String>("�˳�",sevenIcon);
treeItemRoot.getChildren().get(3).getChildren().addAll(Arrays.asList(item_4_1,item_4_2,item_4_3,item_4_4));
treeItemRoot.setExpanded(true);
item_4.setExpanded(true);
treeView.setShowRoot(true);
treeView.setRoot(treeItemRoot);
treeView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TreeItem<String>>() {
@Override
public void changed(ObservableValue<? extends TreeItem<String>> observable, TreeItem<String> oldValue,
TreeItem<String> newValue) {
Parent container = null;
switch (newValue.getValue()) {
case "���¹���":
setSelection(main_center,FRAGMENT_ARTICLE);
break;
case "������":
setSelection(main_center, FRAGMENT_CATEGORY);
break;
case "����":
setSelection(main_center, FRAGMENT_SETTING);
break;
case "����":
setSelection(main_center, FRAGMENT_DEPLOY);
break;
case "ͬ��":
setSelection(main_center, FRAGMENT_SYNC);
break;
case "���ù���":
setSelection(main_center, FRAGMENT_TOOL);
break;
case "�˳�":
Platform.exit();
break;
default:
break;
}
}
});
main_left.getChildren().add(treeView);
intSelection(main_center);
return parent;
}
示例13: start
import javafx.scene.control.TreeView; //导入方法依赖的package包/类
@Override
public void start(Stage primaryStage) throws Exception {
FilterableTreeItem<String> filterableTreeItem = new FilterableTreeItem<>("");
filterableTreeItem.setExpanded(true);
TreeView<String> treeView = new TreeView<>(filterableTreeItem);
treeView.setShowRoot(false);
treeView.setRoot(filterableTreeItem);
BorderPane borderPane = new BorderPane(treeView);
TextField value = new TextField();
value.textProperty().addListener((oba, oldval, newval) -> {
Callable<TreeItemPredicate<String>> func = () -> {
Predicate<String> predicate = str -> str.indexOf(newval) >= 0;
return TreeItemPredicate.<String> create(predicate);
};
ObjectBinding<TreeItemPredicate<String>> createObjectBinding = Bindings.createObjectBinding(func, hide);
filterableTreeItem.predicateProperty().bind(createObjectBinding);
});
borderPane.setTop(value);
Scene scene = new Scene(borderPane);
primaryStage.setScene(scene);
primaryStage.show();
FilterableTreeItem<String> e = new FilterableTreeItem<>("ABC");
// e.getChildren().add(new FilterableTreeItem<>("DEF"));
// e.getChildren().add(new FilterableTreeItem<>("김aa"));
// e.getChildren().add(new FilterableTreeItem<>("김bb"));
// e.getChildren().add(new FilterableTreeItem<>("김cc"));
// filterableTreeItem.getChildren().add(e);
// filterableTreeItem.getChildren().add(new FilterableTreeItem<>("DEF"));
// filterableTreeItem.getChildren().add(new FilterableTreeItem<>("김DD"));
//
e.getSourceChildren().add(new FilterableTreeItem<>("DEF"));
e.getSourceChildren().add(new FilterableTreeItem<>("김aa"));
e.getSourceChildren().add(new FilterableTreeItem<>("김bb"));
e.getSourceChildren().add(new FilterableTreeItem<>("김cc"));
filterableTreeItem.getSourceChildren().add(e);
filterableTreeItem.getSourceChildren().add(new FilterableTreeItem<>("DEF"));
filterableTreeItem.getSourceChildren().add(new FilterableTreeItem<>("김DD"));
// filterableTreeItem.predicateProperty()
// .bind(Bindings.createObjectBinding(() ->
// TreeItemPredicate<String>.create(str -> str.indexOf("김") >= 0),
// hide));
}
示例14: createContent
import javafx.scene.control.TreeView; //导入方法依赖的package包/类
@Override
public Node createContent() {
final BorderPane borderPane = new BorderPane();
factoryLogRootUpdater= root -> {
TreeView<FactoryLogWidgetTreeData> treeView = new TreeView<>();
if (factoryLog.root!=null){
treeView.setRoot(createLogTree(factoryLog.root, System.currentTimeMillis()+5000,new HashMap<>()));
}
treeView.setCellFactory(param-> new TextFieldTreeCell<FactoryLogWidgetTreeData>(){
@Override
public void updateItem(FactoryLogWidgetTreeData item, boolean empty) {
super.updateItem(item, empty);
if (!empty) {
setText(item.getText());
setGraphic(uniformDesign.createIcon(item.getIcon()));
}
}
});
final TabPane tabPane = new TabPane();
tabPane.getStyleClass().add("floating");
final Tab treeTab = new Tab("Updated Tree");
treeTab.setContent(treeView);
tabPane.getTabs().add(treeTab);
final Tab tableTab = new Tab("Updated Table");
tableTab.setContent(treeView);
if (factoryLog.root!=null){
tableTab.setContent(createTable(factoryLog.root.getListDeep()));
}
tabPane.getTabs().add(tableTab);
final Tab removedTab = new Tab("Removed");
removedTab.setContent(treeView);
removedTab.setContent(createTable(factoryLog.removedFactoryLogs));
tabPane.getTabs().add(removedTab);
borderPane.setCenter(tabPane);
final Label totalDuarion = new Label("total update duration: " + (factoryLog.totalDurationNs / 1000000.0) + "ms");
BorderPane.setMargin(totalDuarion,new Insets(3));
borderPane.setTop(totalDuarion);
};
if (factoryLog!=null) {
factoryLogRootUpdater.accept(factoryLog);
}
return borderPane;
}