JTree Drag and Drop: drag nodes with its childs - java

I would like to add drag and drop feature to my JTree.
I have tried to run example from this thread. It works but it works only on last leaves in tree, not on nodes that contain some childs. I have also looked on this thread.
I have defined canImport and importData methods, and also have set setDragEnabled(true). I just cannot drag nodes also with its childs.
How to edit example from first link to drag also nodes with its childs? As I understand correctly, I should set DataFormat instance, to set what types should be dragged.
Can anybody help?

Related

Highlight specific item in treetableview or treeview

I have two TreeViews/TreeTableViews. When clicking on a specific TreeItem in one of those Trees I first collapse the other Tree and then expand only the path to the Item that holds the same information. This is already working nicely.
What is missing still: When expanding the second path of the second Tree I would like Highlight the TreeItem in the second Tree that hold the same information for a shot time( a second or so).
I tried to set it selected and played around setStyle function, which did not have any effect.
Could you give me a hint how to solve this?
Thanks in advance

How to remove tree lines from JideSoft TreeTable

I have created a tree using TreeTable and now that I have all the data in I want to remove the tree lines that are displayed on the left side.
As you can see here:
I want the tree to look like this:
I tried using these lines of code to remove them:
treeTable.setShowGrid(false);
treeTable.setShowHorizontalLines(false);
treeTable.setShowVerticalLines(false);
treeTable.setGridColor(Color.WHITE);
Is there some table property I am missing that can be disabled?
You can use TreeTable.setShowTreeLines() method:
We used the same +/- icons used in JTree so it will change based on
different LookAndFeels. You can also define your own icons by calling
CategorizedTable.setExpandedIcon(javax.swing.Icon) and
CategorizedTable.setCollapsedIcon(javax.swing.Icon). The tree lines
can be turn on or off using setShowTreeLines(boolean). The line color
can be set by setTreeLineColor(java.awt.Color). By default, it will
use the JTree's tree line color which is
UIManagerLookup.getColor("Tree.hash").

Finding the node where an instance belong

I generated a decision tree based on a set of data, then I converted this data to a xml file, after that I put it into a JTree. This part works fine but now I have to take a new instance(which contains the data received from the user), find it's place in the decision tree and change that node's color. And I can't find a way to do that. I am using weka and the J48 classifier to generate the decision tree. The xml is created in the Luc Sorel style: http://www.lucsorel.com/media/downloads/sample_decision_tree.xml
The first thing I tried was to classify the instance using the algorithm but that gets me only the class where it belongs, and I don't know how to locate it in the JTree.
What should I do? Any ideeas?
Like JTable, JTree uses a flyweight renderer to draw nodes. As the default renderer is a JLabel, you can set the foreground color or make the label opaque and set the background color. This related example changes the icon for emphasis. More examples may be found here.
Addendum: I cannot find … the node that I should color.
When getTreeCellRendererComponent() is called, value is a reference to the node to be rendered, and the tree parameter allows access to the TreeModel as a whole via getModel(). This example shows how to search a tree.

How to create inverted JTree in Java?

Actually I'm interested to create an inverted JTree in Java in such a way that root exists at top and its child nodes at the next level and so on. As we know in case of simple JTree the child nodes appears expanding on the right side of the parent node but I want to implement inverted JTree in my project where child nodes expands downwards which gives an appearance of "TREE" type of data structure.
As this is very essential for my project so can anyone suggest me the code for the above mentioned problem?
Thanks in advance.
Then JTree is not the correct choice. Perhaps, you should look into Java2D and stuff like that.

How to get correct selection in a JTreeTable?

I am working with a JTreeTable as described in an old article at: Sun Developer Network
Here are the same files but slightly adjusted for java 6:
http://edtaylor80.angelfire.com
If you run this little example program you will find that selection works as expected to start with, entire rows are selected when you click a random cell. This behaviour is desired. However, as soon as a node is expanded the behaviour changes, now it is only possible to select a row by clicking at the actucal node (name). I still want to be able to select an entire row by clicking a random cell. How can I modify the source code to accomplish this?
Before you click into the first column to open a node, there is no cell editor for the JTable. Once you perform that operation, the table has an active cell editor, which is an instance of the AbstractCellEditor that comes as part of the JTreeTable example source. In the implementation therein, you will find this:
public boolean shouldSelectCell(EventObject anEvent) { return false; }
This gets called by the BasicTableUI when it determines whether to adjust selection or not. As you can see, it will always return false. This is why, once you open a node, you will see this odd selection behavior.
While on the topic of tree tables, I recommend that you check out NetBeans' Outline. It is an easy to use implementation, much less convoluted than the JTreeTable example from Sun. You can find links and a demo in this post.

Categories