Questions tagged [jtree]

Java Swing component that displays a set of hierarchical data as an outline.

JTree is a class in the javax.swing package. It is a Swing component that displays a set of hierarchical data as a tree outline. Like most Swing components, it has a model, is highly configurable through the use of renderers, and fires events that can be handled.

Resources

1222 questions
12
votes
7 answers

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?
Amanda S
  • 3,266
  • 4
  • 33
  • 45
12
votes
5 answers

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?
garyLynch
  • 533
  • 2
  • 4
  • 11
12
votes
4 answers

JTree update nodes without collapsing

I have a Java SE 7 application that needs to have the JTree nodes updated. From the tutorial given by Oracle using this thread, there's no given hint on how I could update the label (displayed text of the node on the Tree) on code. Currently I am…
David B
  • 3,269
  • 12
  • 48
  • 80
11
votes
2 answers

JTree rendering with JCheckBox nodes

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…
craig
  • 25,664
  • 27
  • 119
  • 205
11
votes
4 answers

Double-click a JTree node and get its name

How do I double-click a JTree node and get its name? If I call evt.getSource() it seems that the object returned is a JTree. I can't cast it to a DefaultMutableTreeNode.
Adrian Stamin
  • 687
  • 2
  • 8
  • 21
10
votes
3 answers

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

I am having a jtree with 100 nodes. now i want to search particular node from that tree and make that node expanded..? How can i solve this problem.?
ManthanB
  • 404
  • 2
  • 5
  • 21
10
votes
3 answers

updating JTree in java GUI

I used a JTree in my GUI and added it to a JFrame. When I want to update it and change it's nodes in another part of my program (while program is running, as an action performed) I try to add new nodes, or remove nodes to it; But my interface…
sajad
  • 2,094
  • 11
  • 32
  • 52
10
votes
4 answers

java swing vs mvc: is this pattern indeed possible?

I am new in swing, but managed to create a descend gui. My problem though is that I was not able to apply the patterns suggested in references/tutorials, mainly the MVC pattern. Is it me, or in JTree and using SwingWorker, it is not possible to have…
Cratylus
  • 52,998
  • 69
  • 209
  • 339
10
votes
2 answers

How to get all childs of root node in jtree?

I want to get all child nodes of root node. ex: Root child1 child1.child1 child2 child2.child1 Now I want to get the two child nodes called "child1" and "child2". How to do that? Is there any possibilities? Please help me, Thanks…
Babu R
  • 1,025
  • 8
  • 20
  • 40
9
votes
2 answers

Change icon of the first node of JTree

I want to change just the first node of a JTree icon. There is a file manager that uses JTree to show files. Here is a schematic example. How can I change the icon? Back |->Please wait(this is leaf) Folder 1 |->file1 file2 file3 Folder…
ShirazITCo
  • 1,041
  • 6
  • 23
  • 38
9
votes
2 answers

Change JTree node icons according to the depth level

I'm looking for changing the different icons of my JTree (Swing) The java documentation explains how to change icons if a node is a leaf or not, but that's really not what I'm searching. For me it doesn't matter if a node is a leaf or, I just want…
Soulou
  • 149
  • 1
  • 5
9
votes
1 answer

Color row in JTree

I'd like to color elements in a JTree. However, simply adding a background color only to the label looks kind of strange. Particularly if more than one node is selected, the resulting shape looks ragged and distracting. Is there a way to make the…
MvG
  • 57,380
  • 22
  • 148
  • 276
9
votes
2 answers

JTree set background of node to non-opaque

Please have a look at the SSCCE. How can I make the non-selected tree nodes' background transparent. At the moment the background of non-selected nodes is white. My cell renderer, however, should paint it non-opaque if it is not selected (and green…
haferblues
  • 2,155
  • 4
  • 26
  • 39
9
votes
3 answers

Difficulties understanding the renderers mechanism of swing's JTable and JTree

Often when using JTable or JTree, user define its own cell renderer. It is very common to inherit user's component from DefaultTableCellRenderer, and implements the renderer method getTableCellRendererComponent. It turns out that…
aviad cohen
  • 637
  • 1
  • 6
  • 16
8
votes
3 answers

Sort Jtree Node Alphabetically

I have loaded my JTree to view My directory structure as shown in my code and output image. Here, Tree nodes are by default sorted in alphabetical order, but my other requirement is that I want to sort all nodes according to second name of directory…
Jony
  • 1,035
  • 7
  • 17
  • 43
1
2
3
81 82