Java Code Examples for javafx.scene.control.TreeView#setCellFactory()
The following examples show how to use
javafx.scene.control.TreeView#setCellFactory() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextFieldTreeViewSample.java From marathonv5 with Apache License 2.0 | 6 votes |
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); }
Example 2
Source File: ChoiceBoxTreeViewSample.java From marathonv5 with Apache License 2.0 | 6 votes |
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); }
Example 3
Source File: ComboBoxTreeViewSample.java From marathonv5 with Apache License 2.0 | 6 votes |
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); }
Example 4
Source File: CheckBoxTreeViewSample.java From marathonv5 with Apache License 2.0 | 6 votes |
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); }
Example 5
Source File: TreeViewFactory.java From ariADDna with Apache License 2.0 | 6 votes |
/** * 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()); } }); }
Example 6
Source File: CheckBoxLiveDirs.java From LiveDirsFX with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void start(Stage primaryStage) { TreeView<CheckBoxContentImpl> view = new TreeView<>(); view.setShowRoot(false); view.setCellFactory(TreeCellFactories.checkBoxFactory()); try { // create a LiveDirs instance for use on the JavaFX Application Thread // and make it display its items as though they were CheckBoxTreeItems LiveDirs<ChangeSource, CheckBoxContentImpl> dirs = new LiveDirs<>(ChangeSource.EXTERNAL, CheckBoxContentImpl::getPath, CheckBoxContentImpl::new, Platform::runLater); // set directory to watch dirs.addTopLevelDirectory(Paths.get(System.getProperty("user.home"), "Documents").toAbsolutePath()); view.setRoot(dirs.model().getRoot()); // stop DirWatcher's thread primaryStage.setOnCloseRequest(val -> dirs.dispose()); } catch (IOException e) { e.printStackTrace(); } primaryStage.setScene(new Scene(view, 500, 500)); primaryStage.show(); }
Example 7
Source File: HASCOModelStatisticsPluginView.java From AILibs with GNU Affero General Public License v3.0 | 5 votes |
public HASCOModelStatisticsPluginView(final HASCOModelStatisticsPluginModel model, final int n) { super(model, new VBox()); this.rootNode = new HASCOModelStatisticsComponentSelector(this, model); TreeView<HASCOModelStatisticsComponentSelector> treeView = new TreeView<>(); treeView.setCellFactory(HASCOModelStatisticsComponentCell::new); treeView.setRoot(this.rootNode); this.getNode().getChildren().add(treeView); this.histogram = new Histogram(n); this.histogram.setTitle("Performances observed on the filtered solutions"); this.getNode().getChildren().add(this.histogram); }
Example 8
Source File: ListKMLContentsSample.java From arcgis-runtime-samples-java with Apache License 2.0 | 4 votes |
@Override public void start(Stage stage) { try { // create stack pane and application scene StackPane stackPane = new StackPane(); Scene fxScene = new Scene(stackPane); // set title, size, and add scene to stage stage.setTitle("List KML Contents Sample"); stage.setWidth(800); stage.setHeight(700); stage.setScene(fxScene); stage.show(); // create a map and add it to the map view ArcGISScene scene = new ArcGISScene(Basemap.createImageryWithLabels()); sceneView = new SceneView(); sceneView.setArcGISScene(scene); // load a KML dataset from a local KMZ file and show it as an operational layer File kmzFile = new File(System.getProperty("data.dir"), "./samples-data/kml/esri_test_data.kmz"); KmlDataset kmlDataset = new KmlDataset(kmzFile.getAbsolutePath()); KmlLayer kmlLayer = new KmlLayer(kmlDataset); scene.getOperationalLayers().add(kmlLayer); // create a tree view to list the contents of the KML dataset TreeView<KmlNode> kmlTree = new TreeView<>(); kmlTree.setMaxSize(300, 400); TreeItem<KmlNode> root = new TreeItem<>(null); kmlTree.setRoot(root); kmlTree.setShowRoot(false); // when the dataset is loaded, recursively build the tree view with KML nodes starting with the root node(s) kmlDataset.addDoneLoadingListener(() -> kmlDataset.getRootNodes().forEach(kmlNode -> { TreeItem<KmlNode> kmlNodeTreeItem = buildTree(new TreeItem<>(kmlNode)); root.getChildren().add(kmlNodeTreeItem); })); // show the KML node in the tree view with its name and type kmlTree.setCellFactory(param -> new TextFieldTreeCell<>(new StringConverter<KmlNode>() { @Override public String toString(KmlNode node) { String type = null; if (node instanceof KmlDocument) { type = "KmlDocument"; } else if (node instanceof KmlFolder) { type = "KmlFolder"; } else if (node instanceof KmlGroundOverlay) { type = "KmlGroundOverlay"; } else if (node instanceof KmlScreenOverlay) { type = "KmlScreenOverlay"; } else if (node instanceof KmlPlacemark) { type = "KmlPlacemark"; } return node.getName() + " - " + type; } @Override public KmlNode fromString(String string) { return null; //not needed } })); // when a tree item is selected, zoom to its node's extent (if it has one) kmlTree.getSelectionModel().selectedItemProperty().addListener(o -> { TreeItem<KmlNode> selectedTreeItem = kmlTree.getSelectionModel().getSelectedItem(); KmlNode selectedNode = selectedTreeItem.getValue(); Envelope nodeExtent = selectedNode.getExtent(); if (nodeExtent != null && !nodeExtent.isEmpty()) { sceneView.setViewpointAsync(new Viewpoint(nodeExtent)); } }); // add the map view to stack pane stackPane.getChildren().addAll(sceneView, kmlTree); StackPane.setAlignment(kmlTree, Pos.TOP_LEFT); StackPane.setMargin(kmlTree, new Insets(10)); } catch (Exception e) { // on any error, display the stack trace. e.printStackTrace(); } }
Example 9
Source File: GroupLayersSample.java From arcgis-runtime-samples-java with Apache License 2.0 | 4 votes |
@Override public void start(Stage stage) { try { // set the title and size of the stage and show it StackPane stackPane = new StackPane(); Scene fxScene = new Scene(stackPane); stage.setTitle("Group Layers Sample"); stage.setWidth(800); stage.setHeight(700); // create a JavaFX scene with a stackpane and set it to the stage stage.setScene(fxScene); stage.show(); // create a scene view and add it to the stack pane sceneView = new SceneView(); stackPane.getChildren().add(sceneView); // create a scene with a basemap and add it to the scene view scene = new ArcGISScene(); scene.setBasemap(Basemap.createImagery()); sceneView.setArcGISScene(scene); // set the base surface with world elevation Surface surface = new Surface(); surface.getElevationSources().add(new ArcGISTiledElevationSource("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer")); scene.setBaseSurface(surface); // create different types of layers ArcGISSceneLayer devABuildings = new ArcGISSceneLayer("https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/DevA_BuildingShells/SceneServer"); ArcGISSceneLayer devBBuildings = new ArcGISSceneLayer("https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/DevB_BuildingShells/SceneServer"); ArcGISSceneLayer devATrees = new ArcGISSceneLayer("https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/DevA_Trees/SceneServer"); FeatureLayer devAPathways = new FeatureLayer(new ServiceFeatureTable(" https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/DevA_Pathways/FeatureServer/1")); FeatureLayer devProjectArea = new FeatureLayer(new ServiceFeatureTable("https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/DevelopmentProjectArea/FeatureServer/0")); // create a group layer from scratch by adding the layers as children groupLayer = new GroupLayer(); groupLayer.setName("Group: Dev A"); groupLayer.getLayers().addAll(Arrays.asList(devATrees, devAPathways, devABuildings)); // add the group layer and other layers to the scene as operational layers scene.getOperationalLayers().addAll(Arrays.asList(groupLayer, devBBuildings, devProjectArea)); // zoom to the extent of the group layer when the child layers are loaded groupLayer.getLayers().forEach(childLayer -> childLayer.addDoneLoadingListener(() -> { if (childLayer.getLoadStatus() == LoadStatus.LOADED) { sceneView.setViewpointCamera(new Camera(groupLayer.getFullExtent().getCenter(), 700, 0, 60, 0)); } }) ); // create a JavaFX tree view to show the layers in the scene TreeView<Layer> layerTreeView = new TreeView<>(); layerTreeView.setMaxSize(250, 200); TreeItem<Layer> rootTreeItem = new TreeItem<>(); layerTreeView.setRoot(rootTreeItem); layerTreeView.setShowRoot(false); StackPane.setAlignment(layerTreeView, Pos.TOP_RIGHT); StackPane.setMargin(layerTreeView, new Insets(10)); stackPane.getChildren().add(layerTreeView); // display each layer with a custom tree cell layerTreeView.setCellFactory(p -> new LayerTreeCell()); // recursively build the table of contents from the scene's operational layers buildLayersView(rootTreeItem, scene.getOperationalLayers()); } catch (Exception e) { // on any error, display the stack trace. e.printStackTrace(); } }