treeModel = new DefaultTreeModel(treeRootNode); tree = new JTree(treeModel); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.addMouseListener(new MouseAdapter() { @Override
componentTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); componentTree.addTreeSelectionListener(new TreeSelectionListener() { @Override
widgetTree.setRootVisible(false); widgetTree.setShowsRootHandles(true); widgetTree.getSelectionModel().addTreeSelectionListener(e ->
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setCellRenderer(new CellRenderer()); TreeListener tl = new TreeListener();
tree.setDropMode(DropMode.ON_OR_INSERT); tree.setTransferHandler(new TreeTransferHandler()); tree.getSelectionModel().setSelectionMode( TreeSelectionModel.CONTIGUOUS_TREE_SELECTION); expandTree(tree);
tree.getSelectionModel().setSelectionMode (TreeSelectionModel.SINGLE_TREE_SELECTION); tree.addTreeSelectionListener( new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent treeSelectionEvent) { if (this.tree.getSelectionPaths() != null && this.tree.getSelectionPaths().length > 0) { selectedTreePaths = this.tree.getSelectionModel().getSelectionPaths(); } } }
processList.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); processList .getSelectionModel() .addTreeSelectionListener( new TreeSelectionListener() {
/** Constructor */ public XChartDemo() { super(new GridLayout(1, 0)); // Create the nodes. DefaultMutableTreeNode top = new DefaultMutableTreeNode("XChart Example Charts"); createNodes(top); // Create a tree that allows one selection at a time. tree = new JTree(top); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); // Listen for when the selection changes. tree.addTreeSelectionListener(this); // Create the scroll pane and add the tree to it. JScrollPane treeView = new JScrollPane(tree); // Create Chart Panel chartPanel = new XChartPanel(new AreaChart01().getChart()); // Add the scroll panes to a split pane. splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); splitPane.setTopComponent(treeView); splitPane.setBottomComponent(chartPanel); Dimension minimumSize = new Dimension(130, 160); treeView.setMinimumSize(minimumSize); splitPane.setPreferredSize(new Dimension(700, 700)); // Add the split pane to this panel. add(splitPane); }
protected void init() { // Create the nodes. DefaultMutableTreeNode top = new DefaultMutableTreeNode("XChart Example Charts"); createNodes(top); tree = new JTree(top); // Create a tree that allows one selection at a time. tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); // Listen for when the selection changes. tree.addTreeSelectionListener(this); // Create the scroll pane and add the tree to it. JScrollPane treeView = new JScrollPane(tree); // Create Chart Panel tabbedPane = new JTabbedPane(); for (int i = 0; i < tree.getRowCount(); i++) { tree.expandRow(i); } // select first leaf DefaultMutableTreeNode firstLeaf = top.getFirstLeaf(); tree.setSelectionPath(new TreePath(firstLeaf.getPath())); // Add the scroll panes to a split pane. splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); splitPane.setTopComponent(treeView); splitPane.setBottomComponent(tabbedPane); Dimension minimumSize = new Dimension(130, 160); treeView.setMinimumSize(minimumSize); splitPane.setPreferredSize(new Dimension(700, 700)); // Add the split pane to this panel. add(splitPane); }
/** * Call this method whenever you update the tree and needs it reloaded */ public synchronized void update() { synchronized (this.tree) { this.tree.removeTreeExpansionListener(this); this.tree.removeTreeSelectionListener(this); ((DefaultTreeModel) this.tree.getModel()).reload(); for (TreePath treePath : expandedTreePaths) { this.tree.expandPath(treePath); } this.tree.getSelectionModel().setSelectionPaths(selectedTreePaths); this.tree.addTreeExpansionListener(this); this.tree.addTreeSelectionListener(this); } }
m_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); m_tree.setShowsRootHandles(true); m_tree.setEditable(false);
this.tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.getSelectionModel().setSelectionMode( DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
/** Constructor. */ public ContextTreeView() { tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); }
/** Returns the current selection mode, one of * <code>TreeSelectionModel.SINGLE_TREE_SELECTION</code>, * <code>TreeSelectionModel.CONTIGUOUS_TREE_SELECTION</code> or * <code>TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION</code>. * @since 2.15 * @return selection mode */ public int getSelectionMode() { return tree.getSelectionModel().getSelectionMode(); }
@Override public void actionPerformed(ActionEvent e) { TreePath[] selectedPaths = tree.getSelectionModel().getSelectionPaths(); for (TreePath treePath : selectedPaths) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent(); Clazz userObject = (Clazz) node.getUserObject(); list.add(userObject.toFullString()); } ClassLikeFilter.this.mode = mode; listener.ifPresent(LogFilterValueChangeListener::valueChanged); }
@Override public void actionPerformed(ActionEvent e) { TreePath[] selectedPaths = tree.getSelectionModel().getSelectionPaths(); for (TreePath treePath : selectedPaths) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent(); Clazz userObject = (Clazz) node.getUserObject(); list.remove(userObject.toFullString()); } listener.ifPresent(LogFilterValueChangeListener::valueChanged); }
/** Deinitializes listeners. */ @Override public void removeNotify() { super.removeNotify(); tree.getSelectionModel().removeTreeSelectionListener(managerListener); }
protected void showSelection(TreePath[] treePaths) { tree.getSelectionModel().setSelectionPaths(treePaths); if (treePaths.length == 1) { showPathWithoutExpansion(treePaths[0]); } }