Highlight specific item in treetableview or treeview - java

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

Related

TreeViewer custom node rendering (adding checkboxe and clickeable image)

I'm actually trying to create a tree following that article : https://www.eclipse.org/articles/Article-TreeViewer/TreeViewerArticle.htm
But the problem is that I need to add 2 clickable images (1 for reloading sub-nodes and 1 for adding new sub-node)
And as optional, if someone can explain me how to add a check box on sub-nodes so then I can delete from the parent node all selected sub-nodes
Thank you in advance for all your help

Design a ContextMenu with a TreeView functionality

I want to design a ContextMenu with a TreeView functionality. I didnt found anything how can be done. I want to design a custom TableMenu (that button at the end of table header which can show hide the columns), using a treeView structure in ContextMenu, so the user can show/hide a group of columns, like 1-3, 4-6, and so on, or any kind of grouping, but still keeping the one by one show/hiding. The best way would be a tree structure, so if the user hides the parent all of its children are hidden and vice-versa.
Is there any possibility to adapt somehow the TreeView into ContextMenu?
I would like something like this with CheckBoxes for instance:
Each parent node would be an item that represents a group of columns, and each child would be a column.
P.S.
I know how to create and add a custom ContextMenu as tableMenu (I have got it from here : https://gist.github.com/Roland09/d92829cdf5e5fee6fee9) , I'm interested in how to set a tree structure to context menu instead of the list structure.
I also know that I can add the parent like a "simple" item to the context menu, then handle as a parent, but then I Have to implement every functionality of a TreeItem, but I prefer a much simpler way if it exists.

Uniquely representing tree elements

I want to make my TreeView remember the selected items after refresh/setInput. (Let's pretend the Java TreeView doesn't remember the state). Since the TreeView will get setInput, so the element reference won't persist.
I am thinking to store the selected element by its full path in an ArrayList<String>. (e.g. it looks like ["root_name", "2nd_level_name", "3rd_level_name", "node_name"]). With the full path, I can locate the same element in the refreshed TreeView again.
I was wondering if there's any better way doing this? Or any existing libraries in Java can do this?

How do I pass information from a multi-selection JTree?

I am writing a program that will print information based on selections in a JTree. Multi-selection is enabled, but I haven't been able to figure out how to find out which nodes are selected. Because it is a very large tree, I would prefer to have a Vector of selections which is updated each time a selection/deselection is made, instead of scanning the tree when the print button is pressed. What is the best way of doing this? Thanks in advance for your help.
You can use getSelectionPaths() which will return all selected nodes.

Custom Java JTree implementation

There are 2 JTree: JTree1 and JTree2. Note that the nodes (country, city, colors, blue ...) all will be implemented as JCheckboxes so that user can select particular colors for each city or for the whole country by selecting their corresponding checkboxes.
Problem:
Q1. I want that each country or city can have its own colors selected. Means if a user wants city1.1 to have colors blue and violet and city2.1 to have colors red, then he first have to select the city1.1 checkbox and then select blue and violet, and after that when he selects city2.1, then the checkboxes blue and violet are deselected automatically so that user can select the colors for city2.1. But when the user selects the city1.1 again, then the JTree2should show the selected colors (bule and violet) for city1.1.
So for this purpose, Is the JTree (with its nodes as checkboxes) correct option to implement or I should use some other JComponent?
If JTree is a correct option, then how can I remember the colors of each city?
So for this purpose, Is the JTree
(with its nodes as checkboxes) correct
option to implement or I should use
some other JComponent?
Not exactly sure what you meant, but I, personally, would not use a JTree to present the options on the right hand side. I think it is much simpler to present a JPanel that contains the options in this particular case. Left side seems fine for your example, although I don't really know what sort of data is going into the tree.
If JTree is a correct option, then how
can I remember the colors of each
city?
Note, I'm going to make a couple of assumptions:
The left side that contains your countries and cities remains a JTree and the right hand side can still be a JTree or a JPanel.
You want the options to appear exactly as the user last set it before they select a different node on the left hand side.
The simplest way of achieving this is to add a TreeSelectionListener to the tree's (the one containing the countries and cities) selection model. The TreeSelectionListener is provided with a TreeSelectionEvent which provides the node that was selected and the node that will become selected. This will provide you with the opportunity to extract the colour settings that were set for the node that the selection is changing from to the one that the selection is changing to. The TreeSelectionListener should be added to the TreeSelectionModel that is obtained from the JTree, by calling its getSelectionModel method.
If you use this technique, when you to perform the operation with the last selected options, you'll need to get the options one more time before you perform the operation. For example, if you had a "Save" button, you should check extract the colour settings for which node is selected on the left. This is to capture any changes that the user may have made that the listener has not captured (since the listener is triggered only when the left hand selection changes).
If you need an example, I've written one at http://www.box.net/shared/hgbet4uf6k.

Categories