Filtering on a JTree [closed]

Take a look at this implementation: http://www.java2s.com/Code/Java/Swing-Components/InvisibleNodeTreeExample.htm It creates subclasses of DefaultMutableNode adding a “isVisible” property rather then actually removing/adding nodes from the TreeModel. Pretty sweet I think, and it solved my filtering problem neatly.

Change JTree node icons according to the depth level

As an alternative to a custom TreeCellRenderer, you can replace the UI defaults for collapsedIcon and expandedIcon: Icon expanded = new TreeIcon(true, Color.red); Icon collapsed = new TreeIcon(false, Color.blue); UIManager.put(“Tree.collapsedIcon”, collapsed); UIManager.put(“Tree.expandedIcon”, expanded); TreeIcon is simply an implementation of the Icon interface: class TreeIcon implements Icon { private static final int SIZE = 14; private … Read more

Java Swing: Need a good quality developed JTree with checkboxes

Answering myself: I decided to share my code with everyone. Here’s a screenshot of the result: The implementation details: Created a new class that extends JTree Replaced the ‘TreeCellRenderer’ by a new class I created, that shows a checkbox and a label. The checkbox selection is changed instead of the label background and border. Totally … Read more

Put JTable in the JTree

Get rid of the scrollPane, it’s dysfunctional anyway (so far I agree with Russell 🙂 and add the table and its header to the panel, using an appropriate LayoutManager: public MyTableInTreeCellRenderer() { super(); setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); table = new JTable(); add(table.getTableHeader()); add(table); } you’ll probably need to tweak the visuals a bit, the left and … Read more

How to search a particular node in jtree and make that node expanded.?

Expanding on @mKorbel’s answer and as discussed in How to Use Trees, you can search your TreeModel recursively and obtain a TreePath to the resulting node. Once you have the desired path, it’s easy to reveal it in the tree. tree.setSelectionPath(path); tree.scrollPathToVisible(path); Addendum: Here’s one way to “obtain a TreePath.” private TreePath find(DefaultMutableTreeNode root, String … Read more