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
7
votes
2 answers

How to programmatically fire a MouseEvent to a MouseListener with Java?

I have a JTree with a custom associated MouseListener (for showing popup etc.). I need to fire a MouseEvent that will be caught by the MouseListener. How should I do that programmatically?
michelemarcon
  • 23,277
  • 17
  • 52
  • 68
7
votes
1 answer

JTree make only leaves draggable

I need to make only leaves of a JTree draggable but the following code snippets makes every node in the tree draggable: tree.setDragEnabled(true); How can I restrict the draggable element to specific informationen of a tree node like the property…
jaster
  • 73
  • 2
7
votes
3 answers

Deselect node from JTree when click any place outside the tree

I am using a JTree, which is using a DefaultTreeModel. This tree model has some nodes inside, and when I click on a node, I get the information of the node and I change the background color to show that this node is selected. It is possible to call…
daniel lozano
  • 421
  • 6
  • 19
7
votes
3 answers

JTree Line Style and Nimbus

I am using the Nimbus look and feel. According to this link, you should be able to achieve 3 different line styles with your JTree: While using the following code: theTree.putClientProperty("JTree.lineStyle", "Horizontal"); My JTree looks like…
user489041
  • 27,916
  • 55
  • 135
  • 204
7
votes
1 answer

JTree select item on right click

I know how to get item from selected item my left mouse button click. I can use TreeSelectionListener. tree.addTreeSelectionListener(new TreeSelectionListener(){ @Override public void valueChanged(TreeSelectionEvent tse) { …
SpeedEX505
  • 1,976
  • 4
  • 22
  • 33
7
votes
1 answer

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…
initialZero
  • 6,197
  • 9
  • 29
  • 38
7
votes
1 answer

Change JTree row height resizing behavior when rendering

I want to use a custom TreeCellRenderer containing three text fields only when a node is SELECTED, while use the default renderer when the node is NOT SELECTED. The problem is that although I've set an appropriate preferred and minimum size for the…
7
votes
3 answers

Traversing all nodes of a multi-leveled JTree

I have a JTree with DefaultTreeModel. I need to get to each node of it. Imagine I have this tree: [A] |-[B] |-[C] |-[D] | |-[E] | |-[F] | |-[G] | |-[H] |-[I] |-[J] |-[K] I need to traverse it and print out: ---[A]--- …
cbt
  • 1,271
  • 1
  • 11
  • 20
7
votes
1 answer

Adding vertical padding/space between rows in a JTree?

Is it possible to add some blank space between node rows in a JTree? I am using custom images for the node icons and I guess the images are larger than the standard node icons, so the node icons sit very close together. It would look nicer if there…
XåpplI'-I0llwlg'I -
  • 21,649
  • 28
  • 102
  • 151
7
votes
3 answers

How to get depth of current node in JTree?

I have a JTree with a few nodes and subnodes. When I click on a node I want to know on which depth is it (0, 1, 3). How can I know that? selected_node.getDepth(); doesn't return the depth of current node..
c0dehunter
  • 6,412
  • 16
  • 77
  • 139
6
votes
2 answers

Expand Collapse Expand Issue with JTree Lazy loading

I have implemented a tree using Lazy Loading. The 1st level nodes are created at the time of tree creation, where as the child nodes are created only when a user expands any particular node. The data is coming from DB, and we fire a query to the…
newbie
  • 63
  • 1
  • 4
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
6
votes
2 answers

easy and fast JTree Cell Editor

I have a JTree with a custom TreeModel and a custom TreeRenderer. The Tree Model contains a bunch of objects of different types. One of these types is displayed differently than the others: The displayed text is a concatenation of two fields of the…
Simiil
  • 2,281
  • 1
  • 22
  • 32
6
votes
2 answers

Dynamically resize JTextField in JTree Node

I am using a JPanel with some JLabels and JTextFields as editor and renderer in a JTree. The user can click on any JTextField and modify the text. All works fine. All I am missing is how I can dynamically resize (grow) the JTextField as the user is…
Torsten Römer
  • 3,834
  • 4
  • 40
  • 53
5
votes
2 answers

How do I implement intelligent drag and drop from one JTree to another?

I have two JTrees with some mock data in there, what I'm looking to do is to be able to take each 'Job' (15663-1, 15663-2, etc) and make a node for each, with a node for each part underneath it and the components attached to each part underneath…
davidahines
  • 3,976
  • 16
  • 53
  • 87