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

1204 questions
34
votes
10 answers

Filtering on a JTree

Problem Applying filtering on a JTree to avoid certain nodes/leaves to show up in the rendered version of the JTree. Ideally I am looking for a solution which allows to have a dynamic filter, but I would already be glad if I can get a static filter…
Robin
  • 34,480
  • 5
  • 43
  • 90
29
votes
6 answers

Right-click context menu for Java JTree?

I'm trying to implement pop-up menus in Java JTree. I've sub-classed DefaultTreeCellRenderer (to change node appearance) and DefaultTreeCellEditor (to create Components to attach event listeners to, since apparently the Components that…
arcanex
22
votes
3 answers

Java Swing: Need a good quality developed JTree with checkboxes

I was looking for a a JTree implementation, that contains checkboxes and which: When you select one node, all its successors in the tree are automatically selected When you unselect one node, all its successors in the tree are automatically…
SomethingSomething
  • 9,410
  • 12
  • 56
  • 105
21
votes
5 answers

How do I auto-expand a JTree when setting a new TreeModel?

I have a custom JTree and a custom JModel; I would for the JTree to "auto-expand" when I give it a new model. At the moment, it simply collapse all the nodes to the root. Here is an example: private class CustomTree extends JTree { @Override …
sdasdadas
  • 20,387
  • 19
  • 57
  • 135
20
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
  • 11,378
  • 36
  • 110
  • 192
19
votes
3 answers

Best way to implement tooltips for JTree?

since JTree & TreeModel don't provide tooltips straight out-of-the-box, what do you think, what would be the best way to have item-specific tooltips for JTree? Edit: (Answering my own question afterwards.) @Zarkonnen: Thanks for the getTooltipText…
Touko
  • 10,399
  • 14
  • 71
  • 101
18
votes
5 answers

Java detect CTRL+X key combination on a jtree

I need an example how to add a keyboard handler that detect when Ctrl+C , Ctrl+X , Ctrl+C pressed on a JTree. I were do this before with menu shortcut keys but with no success.
ShirazITCo
  • 1,011
  • 5
  • 23
  • 38
17
votes
8 answers

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…
Paralife
  • 5,754
  • 8
  • 37
  • 57
16
votes
2 answers

Where are these error and warning icons as a java resource?

I've got a custom tree cell renderer that I'm using to render custom icons a JTree, and I really like the warning icon and the error icon that JOptionPane displays for both warning messages and error messages respectively. Obviously I can use the…
Peter
  • 8,395
  • 1
  • 24
  • 24
15
votes
1 answer

Drag and Drop nodes in JTree

I am having difficulty creating a JTree that allows the nodes to be reorganized by dragging and dropping them in the JTree. This seems like it should be relatively simple. I have looked at examples online, but I can not seem to implement it in my…
user489041
  • 26,050
  • 52
  • 126
  • 198
14
votes
2 answers

File.list() vs File.listFiles()

My question is: if this two functions have something different? I mean I know that they return something different, but is it possible that number of elements in one would be different then in the second one. I will try to explain. I implemented…
Fuv
  • 922
  • 2
  • 12
  • 22
13
votes
4 answers

JTree with checkboxes

I need to add checkboxes to a JTree. A custom TreeCellRenderer/TreeCellEditor seems like the right approach. So far I used the CheckBoxNodeRenderer approach in this webpage. It works OK except for two things: there's additional whitespace above +…
Jason S
  • 171,795
  • 155
  • 551
  • 900
13
votes
2 answers

overriding JTree double-click to prevent node expansion?

It looks like there are 2 default mechanisms to expand a folder node in a JTree. One is to click on the expanded/collapsed icon next to a node. The other way is to double-click on the node itself. Is there a way to stop this 2nd mechanism? I would…
Jason S
  • 171,795
  • 155
  • 551
  • 900
13
votes
1 answer

Java: How to programmatically select and expand multiple nodes in a JTree?

I have a JTree and an awt.Canvas. When i select multiple objects from within the Canvas into the objList, I want all the selected items to be shown inside the JTree as selected. That means for example if I have 2 objects selected, both their paths…
Pantaziu Cristian
  • 802
  • 2
  • 12
  • 26
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,178
  • 4
  • 31
  • 45
1
2 3
80 81