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
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
  • 36,233
  • 5
  • 47
  • 99
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
25
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
  • 23,917
  • 20
  • 63
  • 148
24
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
  • 11,491
  • 17
  • 68
  • 126
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
21
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,041
  • 6
  • 23
  • 38
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
  • 11,359
  • 16
  • 75
  • 105
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
  • 6,116
  • 8
  • 38
  • 64
16
votes
2 answers

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
  • 27,916
  • 55
  • 135
  • 204
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,545
  • 1
  • 27
  • 24
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
  • 25
14
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
  • 882
  • 2
  • 14
  • 26
13
votes
2 answers

Set icon to each node in Jtree

I want to set for each node in my JTree a different icon, actually I'm loading each node from a data base, with a "while", I set each icon like a root, leaf or parent. Like this: All my declarations are global: private ResultSet…
Vlad
  • 300
  • 1
  • 4
  • 13
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
  • 184,598
  • 164
  • 608
  • 970
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
  • 184,598
  • 164
  • 608
  • 970
1
2 3
81 82