jtree

Swing question / JTree / custom tree model

Hello, I'm having a problem and hope, someone knows what's going wrong and why and is able to give me the explanation of what I'm missing out right now to make that thing work as suggested. I have a JTree which is build upon a custom TreeModel ("WRTreeModel", see below). The data structure this model shall be used for is build of an ro...

Show/Hide JMenuItems in a JPopupMenu based on a JTree's selection.

I have a JTree which displays a JPopupMenu when I right click nodes in the JTree. What is the best way to hide/show or enable/disable certain JMenuItems in my JPopupMenu based on the node selected in the JTree? The first solution that came to mind was to add a TreeSelectionListener to the JTree for the 'value changed' event. In the even...

Speed up expand/collapse all nodes of a JTree

Hi! I have a JTree with about 100000 nodes or more. Now I want to expand the whole tree. To do so I use the solution I found here. My problem is that expanding such a large tree takes like 60 seconds or more, which is not very convenient. Does anyone have any suggestions how I could speed up expansion? Thanks in advance... ...

How can I refresh a JTree after adding some nodes to the underlying model?

First of all, let me say that I dont use the DefaultTreeModel. I implement my own TreeModel, so i cant use the DefaultXXX stuff. The problem is this: Through some addStuff() methods which my model defines I add nodes to the underlying data structure. I then notify listeners by calling treeNodesChanged() inside the addStuff() function (I ...

Creating Dynamic JTrees (Controlling Root Node Visibility)

I have a question about how to dynamically generate JTrees. Is there a way to set the Root Node invisible without making its children invisible too? I have tried to do the following but it shows all nodes as invisible. Keep in mind that I want to add and remove children of the Root Node at any point in time. I've added comments so you ca...

Java: How to display an XML file in a JTree

Hi, I would like to have a way to display the contents of an XML file in a JTree. I have already accomplished this using DOM, by implementing a custom TreeModel (and TreeCellRenderer). However it is very clunky (much workaround-ery and hackery) and rather rough around the edges. Is anyone aware of a way to get a JTree to display the co...

Problems editing a JCheckBox node in a JTree

I am attempting to modify the standard Swing JTree to intermingle nodes with and without checkboxes. This is an example: When I attempt to check/uncheck one of the checkboxes (the 'User 01' node in this example), the tree loses nodes: I my code is an adaptation of this example: http://forums.sun.com/thread.jspa?threadID=5321084&am...

JTree with left and right-aligned text in cells?

What I'm trying to do is create a JTree with each cell containing normal text but also containing a right-aligned text for each cell (right-aligned to the edge of the tree, regardless of the hierarchy level). I've tried creating my own TreeCellRenderer, but the cells' sizes are not being updated. I also tried this idea with a custom tre...

Jtree node expansion without selection

Hi all, Is it possible to expand/collapse a node in a JTree without having it selected? (not highlighted) Thanks a lot ...

java JTree not updating.

Hello, I am having some issues with JTree. When I create my DefaultTreeModel within the same class, the JFrame updated fine. However, I want to call the update method from another class and when I do the JTree remains blank. The JTree is in the class GUI and stored like so in another class called store. public static GUI UI = new GUI()...

Changing the Node image of a JTree dynamically

I am using a CustomCellRenderer to display nodes of a JTree to display image with a node as shown below :- class CustomTreeCellRenderer extends DefaultTreeCellRenderer{ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)...

JTree node labels change often but width is cached

Currently, I'm using a custom TreeCellRenderer to handle label and icon changes for my JTree. The problem comes when I need to change the text on a few nodes. The TreeCellRenderer works great in that the new text is displayed. However, the width from the initial text is cached and is not updated. I've attempted to hack it by overriding g...

Java: Cut item from JTree with lazy-deleting

I've implemented Drag'n'Drop and CCP on my JTree (I've created my Transferable and TransferHandler classes). By default Cut action (CTRL-X or SHIFT+DELETE keys) delete item from JTree (JTreeModel), but I want just to mark it with gray color and delete it only after Paste action. How could I make Cut action to avoid deleting items? I d...

java swing - add color to my JTree node

I have a created a following renderer which renders the JTree with checkboxes and I want to add different color and icon to different nodes. How do I do it? Please help me. Thank you in advance. class CheckTreeCellRenderer extends JPanel implements TreeCellRenderer { private CheckTreeSelectionModel selectionModel; private TreeCellRender...

JTree component in java swing

How can I change the icon of nodes and root in the JTree component of Swing? ...

Is possible to setting a color into JTree?

I created a tree but i'm unaware of setting color to it. JTree tree; JList list; JFrame frame; tree=new JTree("Tree"); frame.add(tree,BorderLayout.WEST); tree.addTreeSelectionListener(this); frame.add(teamMember,BorderLayout.NORTH); frame.add(list,BorderLayout.CENTER); Is possible to set color in JTree?...

Java - Problem in JTree

There are 2 JTree: JTree1 and JTree2. Note that the nodes (country, city, colors, blue ...) all will be implemented as JCheckboxes so that user can select particular colors for each city or for the whole country by selecting their corresponding checkboxes. Problem: Q1. I want that each country or city can have its own colors selected...

JTree of objects?

Hello, How I can implement dynamic Jtree, which shows created instances of clases? For example, I can create new Book(name) in my app. In every book can be chapters = ArrayList of Chapter. And now How I can do a jtree from it? ...

How to do something like listener of creating instances in other module?

Hello, I have module GUI, which has JTRee. And 2nd module creates ArrayLists of my own defined objects, which have some structure. For example car = new Car(); car.addEngine(new Engine("eng")); car.getEngine("eng").addWheel(new Wheel()); How to do my JTree in GUI module listens creating of objects in 2nd module and adding it to JTree? ...

Java Swing - Should JTree be used with TreeModel - MVC desing pattern

I am going to use JTree in my Java Swing Desktop Application. I read about MVC Design pattern and according to it, we should use Model classes of Swing Components to separate the datamodel of a JComponent from its presentation part. So my quick question is as follows: JTree(TreeModel newModel) JTree(Object[] value) JTree...