Questions tagged [treemodel]

109 questions
21
votes
1 answer

Adding and removing nodes from a JTree

I have a very basic JTree. As I am on a rush, I'd prefer not to use TreeModel if it is not needed. I wrote a SSCCE to expose the problem: Sometimes I add a node. Other times I remove them. When I push Add, a node is correctly added. When I push…
Roman Rdgz
  • 12,836
  • 41
  • 131
  • 207
8
votes
3 answers

store state/expanded nodes of a jtree for restoring state

I am working with JTree. I would like to know what is best the way to know which nodes are expanded in a JTree so as to save its state (i.e. save all expanded paths). So that if I call model.reload() the Jtree would not stay collapsed, but I will be…
Cratylus
  • 52,998
  • 69
  • 209
  • 339
7
votes
4 answers

Cloning a JS TreeModel tree

I need to clone a tree I made using TreeModel.js. What I exactly need to do is duplicating it, make changes to it and check if the number of nodes decreased. If it did, revert to the original tree. Here's a small example of what I do so far to…
Johy
  • 317
  • 1
  • 5
  • 16
5
votes
1 answer

Jtree to JPanel

I have a JTree object which uses DefaultTreeModel as model and I add/remove nodes respect to that model. At that point, I need to show tree structure in graphical interface such as JPanel. How can I map DefaultTreeModel elements into Jpanel object?…
Okan Çetin
  • 85
  • 1
  • 4
5
votes
1 answer

Java: How to display an XML file in a JTree

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…
bguiz
  • 27,371
  • 47
  • 154
  • 243
5
votes
3 answers

JDialog - Refresh dynamically added nodes in JTree

I have a problem with JTree nodes visibility I use for my JDialog. When I want to add new node to the model the Jtree is not refreshed. Strange is the nodes are updating just as they should if I set setRootVisible(true). Here is the code. Thanks in…
bioMind
  • 171
  • 1
  • 2
  • 9
4
votes
1 answer

Transforming a tree back to JSON using tree-model-js

Is there perhaps a way in which you can convert a TreeModel to a JSON string. That way it can be stored and then later recreated using tree.parse()? Currently when attempting JSON.stringify(root) it gives an obvious error about cyclic references…
cornelius7
  • 103
  • 5
4
votes
3 answers

Java Swing: how do I define how a JTree displays the "user object"?

When using a JTree, a "user object" of a DefaultMutableTreeNode can be set. This can be of any kind, but to display it, its toString() value is used. This is not what I need. How can I change the way a user object is displayed? NOTE: My user object…
java.is.for.desktop
  • 10,748
  • 12
  • 69
  • 103
4
votes
1 answer

How to make Qt navigate tree items fast?

I developed a Qt tree with 1,000,000 items under a node. The code is similar to its simple tree model example at http://qt-project.org/doc/qt-5.0/qtwidgets/itemviews-simpletreemodel.html . When I click key "End", it takes 15 seconds to go to the…
user1899020
  • 13,167
  • 21
  • 79
  • 154
4
votes
2 answers

Java Jtree populated by SQL query

I would like to create a JTree from a two dimensional object array that I will import from a SQL query. This is what the SQL table looks like: Here is sample of the object: Object[][] table = { {1, 0, "Root"}, //i=0 {2, 1,…
ForgottenKahz
  • 268
  • 3
  • 24
3
votes
2 answers

Java Custom Tree Model updating problem

Here is structure of the tree: root -branches --leafs I use for TreeModel DefaultTreeModel and my objects implement TreeNode interface leaf is some Object: public class Leaf implements TreeNode { // implementation branch has List of…
Artyom Chernetsov
  • 1,394
  • 4
  • 17
  • 34
3
votes
2 answers

Why isn't my JTree updating when the TreeModel adds new nodes?

I am using a DefaultTreeModel populated with an override of DefaultMutableTreeNode which supports optionally changing the display string of a node in a tree. As shown in the code below, in my form I populate the tree with new nodes by creating them…
Caleb Hearth
  • 3,315
  • 5
  • 30
  • 44
3
votes
1 answer

get underlying node data on clicked node on JTree?

basically I am using dom4j library to render the DefaultTreeModel into JTree. DefaultTreeModel parses XML document. Each XML node contains information like attributes, name, id etc. Basically, I add a actionlistener to this Jtree. I would like to…
KJW
  • 15,035
  • 47
  • 137
  • 243
3
votes
2 answers

Java Swing JTree TreeModel - how to do lazy inialization

I have a JTree in my swing app, to display a long list of data (int tree mode). the issue is that TreeModel loading all items during initialization and I don't need to load them all. in one screen only 100 of them are displayable so no point to load…
mhshams
  • 16,384
  • 17
  • 55
  • 65
3
votes
2 answers

expand Jtree at last modified area?

I am using dom4j to create a DocumentTreeModel from a dom4j document. I display this DocumentTreeModel inside JScrollPane. I have a button that adds a new node to the dom4j document, and recreates the DocumentTreeModel I am using getPathForRow but…
KJW
  • 15,035
  • 47
  • 137
  • 243
1
2 3 4 5 6 7 8