Java Code Examples for javax.swing.tree.DefaultTreeModel#addTreeModelListener()
The following examples show how to use
javax.swing.tree.DefaultTreeModel#addTreeModelListener() .
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: Test8015926.java From jdk8u_jdk with GNU General Public License v2.0 | 10 votes |
@Override public void run() { Thread.currentThread().setUncaughtExceptionHandler(this); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child"); DefaultTreeModel model = new DefaultTreeModel(root); this.tree = new JTree(); this.tree.setModel(model); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(this.tree); model.addTreeModelListener(this); // frame is not visible yet model.insertNodeInto(child, root, root.getChildCount()); model.removeNodeFromParent(child); frame.setSize(640, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); }
Example 2
Source File: Test8015926.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public void run() { Thread.currentThread().setUncaughtExceptionHandler(this); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child"); DefaultTreeModel model = new DefaultTreeModel(root); this.tree = new JTree(); this.tree.setModel(model); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(this.tree); model.addTreeModelListener(this); // frame is not visible yet model.insertNodeInto(child, root, root.getChildCount()); model.removeNodeFromParent(child); frame.setSize(640, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); }
Example 3
Source File: Test8015926.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
@Override public void run() { Thread.currentThread().setUncaughtExceptionHandler(this); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child"); DefaultTreeModel model = new DefaultTreeModel(root); this.tree = new JTree(); this.tree.setModel(model); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(this.tree); model.addTreeModelListener(this); // frame is not visible yet model.insertNodeInto(child, root, root.getChildCount()); model.removeNodeFromParent(child); frame.setSize(640, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); }
Example 4
Source File: Test8015926.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Override public void run() { Thread.currentThread().setUncaughtExceptionHandler(this); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child"); DefaultTreeModel model = new DefaultTreeModel(root); this.tree = new JTree(); this.tree.setModel(model); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(this.tree); model.addTreeModelListener(this); // frame is not visible yet model.insertNodeInto(child, root, root.getChildCount()); model.removeNodeFromParent(child); frame.setSize(640, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); }
Example 5
Source File: Test8015926.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
@Override public void run() { Thread.currentThread().setUncaughtExceptionHandler(this); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child"); DefaultTreeModel model = new DefaultTreeModel(root); this.tree = new JTree(); this.tree.setModel(model); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(this.tree); model.addTreeModelListener(this); // frame is not visible yet model.insertNodeInto(child, root, root.getChildCount()); model.removeNodeFromParent(child); frame.setSize(640, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); }
Example 6
Source File: Test8015926.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
@Override public void run() { Thread.currentThread().setUncaughtExceptionHandler(this); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child"); DefaultTreeModel model = new DefaultTreeModel(root); this.tree = new JTree(); this.tree.setModel(model); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(this.tree); model.addTreeModelListener(this); // frame is not visible yet model.insertNodeInto(child, root, root.getChildCount()); model.removeNodeFromParent(child); frame.setSize(640, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); }
Example 7
Source File: Test8015926.java From hottub with GNU General Public License v2.0 | 6 votes |
@Override public void run() { Thread.currentThread().setUncaughtExceptionHandler(this); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child"); DefaultTreeModel model = new DefaultTreeModel(root); this.tree = new JTree(); this.tree.setModel(model); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(this.tree); model.addTreeModelListener(this); // frame is not visible yet model.insertNodeInto(child, root, root.getChildCount()); model.removeNodeFromParent(child); frame.setSize(640, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); }
Example 8
Source File: Test8015926.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Override public void run() { Thread.currentThread().setUncaughtExceptionHandler(this); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child"); DefaultTreeModel model = new DefaultTreeModel(root); this.tree = new JTree(); this.tree.setModel(model); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(this.tree); model.addTreeModelListener(this); // frame is not visible yet model.insertNodeInto(child, root, root.getChildCount()); model.removeNodeFromParent(child); frame.setSize(640, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); }
Example 9
Source File: Test8015926.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override public void run() { Thread.currentThread().setUncaughtExceptionHandler(this); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child"); DefaultTreeModel model = new DefaultTreeModel(root); this.tree = new JTree(); this.tree.setModel(model); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(this.tree); model.addTreeModelListener(this); // frame is not visible yet model.insertNodeInto(child, root, root.getChildCount()); model.removeNodeFromParent(child); frame.setSize(640, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); }
Example 10
Source File: Test8015926.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Override public void run() { Thread.currentThread().setUncaughtExceptionHandler(this); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child"); DefaultTreeModel model = new DefaultTreeModel(root); this.tree = new JTree(); this.tree.setModel(model); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(this.tree); model.addTreeModelListener(this); // frame is not visible yet model.insertNodeInto(child, root, root.getChildCount()); model.removeNodeFromParent(child); frame.setSize(640, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); }
Example 11
Source File: Test8015926.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public void run() { Thread.currentThread().setUncaughtExceptionHandler(this); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child"); DefaultTreeModel model = new DefaultTreeModel(root); this.tree = new JTree(); this.tree.setModel(model); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(this.tree); model.addTreeModelListener(this); // frame is not visible yet model.insertNodeInto(child, root, root.getChildCount()); model.removeNodeFromParent(child); frame.setSize(640, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); }
Example 12
Source File: Test8015926.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override public void run() { Thread.currentThread().setUncaughtExceptionHandler(this); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child"); DefaultTreeModel model = new DefaultTreeModel(root); this.tree = new JTree(); this.tree.setModel(model); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(this.tree); model.addTreeModelListener(this); // frame is not visible yet model.insertNodeInto(child, root, root.getChildCount()); model.removeNodeFromParent(child); frame.setSize(640, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); }
Example 13
Source File: Test8015926.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Override public void run() { Thread.currentThread().setUncaughtExceptionHandler(this); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child"); DefaultTreeModel model = new DefaultTreeModel(root); this.tree = new JTree(); this.tree.setModel(model); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(this.tree); model.addTreeModelListener(this); // frame is not visible yet model.insertNodeInto(child, root, root.getChildCount()); model.removeNodeFromParent(child); frame.setSize(640, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); }
Example 14
Source File: DynamicTree.java From marathonv5 with Apache License 2.0 | 5 votes |
public DynamicTree() { super(new GridLayout(1, 0)); rootNode = new DefaultMutableTreeNode("Root Node"); treeModel = new DefaultTreeModel(rootNode); treeModel.addTreeModelListener(new MyTreeModelListener()); tree = new JTree(treeModel); tree.setEditable(true); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setShowsRootHandles(true); JScrollPane scrollPane = new JScrollPane(tree); add(scrollPane); }
Example 15
Source File: ObjectSelector.java From jaamsim with Apache License 2.0 | 5 votes |
public ObjectSelector() { super( "Object Selector" ); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(FrameBox.getCloseListener("ShowObjectSelector")); addWindowFocusListener(new MyFocusListener()); top = new DefaultMutableTreeNode(); treeModel = new DefaultTreeModel(top); tree = new JTree(); tree.setModel(treeModel); tree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION ); tree.setRootVisible(false); tree.setShowsRootHandles(true); tree.setInvokesStopCellEditing(true); treeView = new JScrollPane(tree); getContentPane().add(treeView); entSequence = 0; addComponentListener(FrameBox.getSizePosAdapter(this, "ObjectSelectorSize", "ObjectSelectorPos")); tree.addTreeSelectionListener( new MyTreeSelectionListener() ); treeModel.addTreeModelListener( new MyTreeModelListener(tree) ); tree.addMouseListener(new MyMouseListener()); tree.addKeyListener(new MyKeyListener()); }
Example 16
Source File: RedisFragmentedKeyTreeModel.java From nosql4idea with Apache License 2.0 | 5 votes |
private void updateFilteredModel() { DefaultMutableTreeNode sourceRoot = (DefaultMutableTreeNode) super.getRoot(); DefaultMutableTreeNode targetRoot = (DefaultMutableTreeNode) sourceRoot.clone(); wrapNodes(sourceRoot, separator); fragmentedKeyModel = new DefaultTreeModel(targetRoot); Object[] listeners = listenerList.getListenerList(); for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == TreeModelListener.class) { fragmentedKeyModel.addTreeModelListener((TreeModelListener) listeners[i + 1]); } } fireSeparatorChanged(); }
Example 17
Source File: MainPanel.java From java-swing-tips with MIT License | 4 votes |
private MainPanel() { super(new BorderLayout()); FileSystemView fileSystemView = FileSystemView.getFileSystemView(); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultTreeModel treeModel = new DefaultTreeModel(root); Stream.of(fileSystemView.getRoots()).forEach(fileSystemRoot -> { DefaultMutableTreeNode node = new DefaultMutableTreeNode(new CheckBoxNode(fileSystemRoot, Status.DESELECTED)); root.add(node); Stream.of(fileSystemView.getFiles(fileSystemRoot, true)) .filter(File::isDirectory) .map(file -> new CheckBoxNode(file, Status.DESELECTED)) .map(DefaultMutableTreeNode::new) .forEach(node::add); }); treeModel.addTreeModelListener(new CheckBoxStatusUpdateListener()); JTree tree = new JTree(treeModel) { @Override public void updateUI() { setCellRenderer(null); setCellEditor(null); super.updateUI(); // ???#1: JDK 1.6.0 bug??? Nimbus LnF setCellRenderer(new FileTreeCellRenderer(fileSystemView)); setCellEditor(new CheckBoxNodeEditor(fileSystemView)); } }; tree.setRootVisible(false); tree.addTreeSelectionListener(new FolderSelectionListener(fileSystemView)); tree.setEditable(true); tree.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); tree.expandRow(0); // tree.setToggleClickCount(1); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(new JScrollPane(tree)); // // TEST // add(new JButton(new AbstractAction("test") { // private void searchTreeForCheckedNode(TreePath path) { // Object o = path.getLastPathComponent(); // if (!(o instanceof DefaultMutableTreeNode)) { // return; // } // DefaultMutableTreeNode node = (DefaultMutableTreeNode) o; // o = node.getUserObject(); // if (!(o instanceof CheckBoxNode)) { // return; // } // CheckBoxNode check = (CheckBoxNode) o; // if (check.getStatus() == Status.SELECTED) { // System.out.println(check.getFile().toString()); // } else if (check.getStatus() == Status.INDETERMINATE && !node.isLeaf()) { // // Java 9: Enumeration<TreeNode> e = node.children(); // Enumeration<?> e = node.children(); // while (e.hasMoreElements()) { // searchTreeForCheckedNode(path.pathByAddingChild(e.nextElement())); // } // } // } // // @Override public void actionPerformed(ActionEvent e) { // System.out.println("------------------"); // searchTreeForCheckedNode(tree.getPathForRow(0)); // // DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot(); // // // Java 9: Enumeration<TreeNode> e = root.breadthFirstEnumeration(); // // Enumeration<?> e = root.breadthFirstEnumeration(); // // while (e.hasMoreElements()) { // // DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement(); // // CheckBoxNode check = (CheckBoxNode) node.getUserObject(); // // if (Objects.nonNull(check) && check.getStatus() == Status.SELECTED) { // // System.out.println(check.getFile().toString()); // // } // // } // } // }), BorderLayout.SOUTH); setPreferredSize(new Dimension(320, 240)); }