jtree

Java TreeNode: How to prevent getChildCount from doing expensive operation?

I'm writing a Java Tree in which tree nodes could have children that take a long time to compute (in this case, it's a file system, where there may be network timeouts that prevent getting a list of files from an attached drive). The problem I'm finding is this: getChildCount() is called before the user specifically requests opening a...

Best way to implement tooltips for JTree?

Hi, since JTree & TreeModel don't provide tooltips straight out-of-the-box, what do you think, what would be the best way to have item-specific tooltips for JTree? Edit: (Answering my own question afterwards.) @Zarkonnen: Thanks for the getTooltipText idea. I found out another (maybe still a bit nicer) way with overriding DefaultTr...

The Big Tree: When to Release Data in an RIA

This question is about a Java JTree or a Window .Net Tree (Winforms) or an Adobe Flex Tree. In a client-server application (for Flex it's Web, really), I have a tree with hierarchical data (in a Windows Explorer type interface). Right now I lazily load up the tree as the user requests more data from the server. This is fine and will wor...

Is there a way to have expander icons for multiple roots in a JTree?

I have a JTree with multiple "roots" (Of course, I actually have an invisible real root with multiple children). The nodes expand and collapse on double click, but there's no visual indication that you can do this as there is no expander icon. This is made worse by the fact that the tree is collapsed by default, but expanding the "root...

JTree gives ArrayIndexOutOfBoundsException?

I try to dynamically add nodes to a Java Swing JTree, and the user should be able to browse and to collapse hierarchy while nodes are constantly added. When I add a Thread.sleep(10) in my loop, it works fine; but this is a dirty hack... Here is the stripped down code that triggers this problem. Whenever I run this and doubleclick on the...

Java JTree expand only level one nodes

With a JTree, assuming the root node is level 0 and there may be up to 5 levels below the root, how can I easily expand all the level 1 nodes so that all level 1 & 2 branches and leafs are visible but levels 3 and below aren't? ...

Right-click context menu for Java JTree?

I'm trying to implement pop-up menus in Java JTree. I've sub-classed DefaultTreeCellRenderer (to change node appearance) and DefaultTreeCellEditor (to create Components to attach event listeners to, since apparently the Components that DefaultTreeCellRenderer.getTreeCellRendererComponent() returns can't do it?). I don't really want to "e...

Not able to highlight the file in JTree

Hi, I have created a JTree in which I want to highlight a file and if the directory containing the file is invisible, I need to expand it. Ex: I have created a JTree with the root node- D:/Company/abb/src. The file which I want to highlight is - D:/Company/abb/src/bin/help.txt Please give me some logic to highlight the file help.txt. ...

Can I stop JTree caching nodes (in a file system tree)?

I have a JTree implementation for directories in the file system. The problem I have is that when a directory is removed or renamed, the tree still shows the directory in it's parent. The parent tree seems not to be updated for any changes once a node has been expanded. The model I have written does not cache (I have commented out what...

how to set JTree "ctrl" selection mode to be always enabled

Hello, I have a JTree that implements multi selection logic. This works great when I do all my selections using the mouse + Ctrl key pressed. If user makes selections with the Ctrl key unpressed it breaks my logic. I can't really see why it breaks but I think that a possible solution is to always indicate the TreeSelectionModel that t...

Reloading a JTree during runtime

I create a JTree and model for it out in a class separate to the GUI class. The data for the JTree is extracted from a file. Now in the GUI class the user can add files from the file system to an AWT list. After the user clicks on a file in the list I want the JTree to update. The variable name for the JTree is schemaTree. I have the f...

Selection Path of a JTree

I've loaded a JTree with nodes from an XML Schema file using the XSOM API (https://xsom.dev.java.net). Every time a file is selected I do the folowing: schemaParser = new XSDParser(selectedFile.getAbsolutePath()); TreeModel model = schemaParser.generateTreeModel(); schemaTree.setModel(model); schemaTree.setCellRenderer(new SchemaTreeT...

Hiding/filtering nodes in a JTree?

I have a data object represented in a TreeModel, and I'd like to show only part of it in my JTree--for the sake of argument, say the leaves and their parents. How can I hide/filter the unnecessary nodes? ...

How to change JTree view dynamically when a nodes object's state changes?

I'm implementing a Java JTree panel. This panel holds a TreeModel build from a set ofdatastructures that are treelike (a list of lists of composites - different classes). I get these datastructure from external jar implementations based on a set of interfaces I defined. The treenodes contain a checkbox that the user may check to indicat...

Swing: How could I use JTree with JTextPanes as nodes?

JTree uses DefaultTreeCellRenderer as cell renderer. This class is a subclass of JLabel. I want to use JTree with more complex elements than JLabel, such as JTextPane. Problem is: I can't subclass DefaultTreeCellRenderer, because it would still be a JLabel. Writing an own TreeCellRenderer is too complex. Why? Because: DefaultTreeCell...

How to turn off key handling on BasicTreeUI

BasicTreeUI (in JDK 1.5) handles key events on JTree by navigating to an item on the tree that starts with that letter. What is the most straight forward way to turn that behavior off? ...

Where are these icons as a java resource?

I've got a custom tree cell renderer that I'm using to render custom icons a JTree, and I really like the warning icon and the error icon that JOptionPane displays for both warning messages and error messages respectively. Obviously I can use the following code to get the icons for my own use, but this is way heavy handed and requires me...

overriding JTree double-click to prevent node expansion?

It looks like there are 2 default mechanisms to expand a folder node in a JTree. One is to click on the expanded/collapsed icon next to a node. The other way is to double-click on the node itself. Is there a way to stop this 2nd mechanism? I would like to override the double-click on a node so it does something (updates another display ...

JTree with checkboxes

I need to add checkboxes to a JTree. A custom TreeCellRenderer/TreeCellEditor seems like the right approach. So far I used the CheckBoxNodeRenderer approach in this webpage. It works OK except for two things: there's additional whitespace above + below the checkbox; I'd like to keep it the same as a regular JTree. I would like to disti...

Drag and drop feedback in a JTree with custom TreeCellRenderer (Java, Swing)

I have a class derived from JTree with custom TreeCellRenderers. I have implemented drag and drop in that tree, so a user can rearrange tree nodes. The drop mode is DropMode.ON_OR_INSERT, so the user can drop nodes on or between other nodes. While the user is dragging the node, if the pointer points between nodes, a blue line is drawn i...