Questions tagged [defaulttreemodel]

A DefaultTreeModel is a default implementation for displaying JTree data in Java Swing.

DefaultTreeModel is a class in the javax.swing.tree package. It is the default implementation model for displaying data to be represented by a JTree.

23 questions
6
votes
1 answer

Restore Expansion/Selection State in JTree with Lazy Loading

I have an application which contains a JTree backed with a DefaultTreeModel that is used to display a hierarchy of files which reflects a section of the file system on my server (I will refer to this as my client app). I also have a server…
Jeremy
  • 771
  • 6
  • 15
4
votes
1 answer

JTree Edit Root Node?

I am trying to create a JTree I can edit later. So far I have the following code which generates the tree with root node as expected. But, when the button is clicked (triggering the action listener) it adds another node under the root node. What I…
Kyle
  • 2,339
  • 10
  • 33
  • 67
4
votes
2 answers

JTree with form builder

I created a form with default NetBeans edito and put a jTree on it. It somehow then creates bunch of elements such as "colors", "sports", "food" in there. But it is not in the creation code. Where is it coming from and how can I edit it... Even if I…
NewProger
  • 2,945
  • 9
  • 40
  • 58
2
votes
1 answer

Expand and Collapse two trees with same structure simultaneously

I want to modify the standard JTree in Swing example as given in this link -> Dynamic Tree Example A screenshot of the app is below: DynamicTreeDemo I want to use this structure to maintain two trees, both having exactly the same structure. I…
TSG
  • 877
  • 1
  • 6
  • 23
1
vote
1 answer

insertNodeInto function only works in first insertion (works for leaf node)

Say I'm coding for an editable tree file system and adding an action listener for my "add child" button. That is, once I select a node in the tree and click the "Add child" button. There should be a new node "New" becoming its child, which was…
1
vote
1 answer

Cannot add leaf to Jtree

I am tryng to build a Tree, but I cannot add any leaf, only be able to add to the root. Below an example do you have any help? Thanks, Gianluca import java.awt.Dimension; import java.util.ArrayList; import javax.swing.JDialog; import…
1
vote
3 answers

Is it necessary to call nodesWereInserted() and similar methods in DefaultTreeModel?

In DefaultTreeModel, you can insert a node using the insertNodeInto() methods. However, I noticed that there also exists the nodesWereInserted() method that has this very terse Javadoc: Invoke this method after you've inserted some TreeNodes into…
Thunderforge
  • 19,637
  • 18
  • 83
  • 130
1
vote
1 answer

How to unregister JTree from TreeModel while it is not visible?

How can I get a JTree to only listen to its TreeModel while it is actually visible to the user or at least to have it unregister itself as soon as the corresponding JFrame is disposed? As far as I can see the only case a JTree unregisters itself…
siegi
  • 5,646
  • 2
  • 30
  • 42
1
vote
1 answer

Compound JTree Node allowing events to pass through to objects underneath

Compound JTree Node allowing events to pass through to objects underneath I went through the answer by @Jakub Zaverka ,which was pretty lucid.But what I could not understand is where is the code to create tree nodes (JTree ,food,sports,colors).…
Sameer Sarmah
  • 1,052
  • 4
  • 15
  • 33
1
vote
2 answers

Dynamically populating the tree model from a text file in JTree

The problem I am facing is with the tree model of the JTree. I have defined the root node as: javax.swing.tree.DefaultMutableTreeNode rootNode = new javax.swing.tree.DefaultMutableTreeNode(projectName); When the application first starts, I want…
vhora
  • 320
  • 2
  • 16
0
votes
0 answers

DefaultTreeModel methods are executing slowly in some circumstances

I have a method that recalculates all nodes of the passed bunch. In some environments, I have an issue with delays (about 15ms) calling methods of the DefaultTreeModel class such as getChildCount, getChild, insertNodeInto. Interesting enough this…
ngranin
  • 181
  • 2
  • 14
0
votes
1 answer

Swing throws ArrayIndexOutOfBoundsException while relocating nodes in JTree

I want to change location of some nodes in my JTree. Here is the code: public void changeNodePositionInTree() { DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); for(int i = 0; i < someList.size(); i++) { …
polis
  • 795
  • 7
  • 23
0
votes
1 answer

Saving expanded state of JTree when adding elements to nodes

Hello I have question regarding saving expansion state when change DefaultTreeModel. Currently I have a jTree which looks like this: If I select an item from the left JList and select a TestGr from right Jtree and click on Add Test Case button it…
stewazy
  • 139
  • 1
  • 3
  • 8
0
votes
1 answer

Expanding specific JTree Node with FileTree as TreeModel

I am trying to build JTree based file browser and trying to navigate to particular path using setSelectionPath with DefaultMutableTreeNode. I have taken the reference of the code from here import java.io.File; import java.util.Arrays; import…
Dinesh
  • 16,014
  • 23
  • 80
  • 122
0
votes
1 answer

Why does node selection not work properly after TreeModel reload?

I have a Swing application that uses a JTree. I want some of the nodes of the tree to be hidden, so I have implemented two DefaultTreeModels, one with every node and a filtered one with only the ones that should be displayed. The latter is set as…
Robin
  • 1
  • 1
  • 2
1
2