Duplicating a JavaFx group node loaded from FXML in run time - java

I am trying duplicate a group node which i designed in scene builder. Then add the same to a vertical box below to the same node.
The group node contains a label, text field and a button. When i click the button it should add a duplicate group node below
I tried using
FXCollections.copy(dest, src);
by passing the observable list into it. But the vbox says duplicate id.
If there are any good ideas. pls let me know.

Related

Getting a Boolean value JAVAFX

I have a group of nodes within a GridPane and have some listeners adding and removing those nodes from the GridPane.
I was wondering if there is a way for me to create a get method(Boolean) or such to test if the nodes are currently in the GridPane or not.
I want to enable the button when the nodes aren't in the gridpane aka false.
Any help/thoughts appreciated!
That's how you can check for the presence of a node:
gridpane.getChildren().contains(yourNode);
You can check if the parent of the Node node that you want to check is the GridPane. This should be a bit faster than using the child list, since it does not require iterating through the child list:
node.getParent() == gridPane
You can also use bindings to enable/disable the button (assuming there is a single node that decides, if the Button should be enabled or disabled)
button.disableProperty().bind(node.parentProperty().isEqualTo(gridPane));

How can I tell what nodes are highlighted on a displayed JTree?

I'm working on an app that displays a JTree. I want the user to be able to highlight certain nodes and then do things to those nodes after they press a button.
Highlighting already works - they can click on things, and then shift-click or control click to highlight other things. is there any way to detect which nodes are highlighted in this way?
Thanks!
If I'm understanding you correctly you want to find all the tree nodes that a user has selected. See JTree.getSelectionPaths(). The Javadoc states that it returns
An array of TreePath objects indicating the selected nodes, or null if nothing is currently selected
Each TreePath
represents an array of objects that uniquely identify the path to a node in a tree. The elements of the array are ordered with the root as the first element of the array
As #MadProgrammer states in the comment the last object in the array is the selected node.
You can create a TreeSelectionListener as follows and use e.paths from the TreeSelectionEvent:
jTree.addTreeSelectionListener(new TreeSelectionListener() {
#Override
public void valueChanged(TreeSelectionEvent e) {
// e.paths has the selected nodes in the TreeModel
}
});

treeviewer does not deselect the tree item

I wanted to create dynamic tree struture in my application.
There my requirement is When the user selects any tree node
and click insert the child should be inserted below the selected parent. That is working fine. Now the problem is
i am unable to deselect the currently selected tree item in order to change tree item .
I clicked the background of the view and tried to insert
a new tree item, but still it goes to the previously selected tree node as still it highlight as the selected one. How to solve this issue?
If you create a TreeViewer with style SWT.SINGLE then the tree will insist on keeping an item selected unless you explicitly clear the selection.
To clear a selection use:
treeViewer.setSelection(StructuredSelection.EMPTY);
If you use SWT.MULTI as the tree style you can clear the selection with Ctrl+Click

Root immediate child nodes icons not visible when hiding root

I have a JTree structure as shown below. I have Icons that appear whenever a node has child nodes, which is working properly.
My problem is that I need to hide the ROOT node. When I hide the ROOT node, the Icons for MainTop1 and MainTop2 nodes are not displayed, even though they have children. To hide ROOT node I'm using "setRootVisible(false)".
Also when ROOT node is hidden, the Icons for Topic1 and Topic nodes are displayed properly.
Anyone knows how to display the Icons for MainTop1 and MainTop2 when ROOT is hidden? Thanks in advance.
Below is my tree structure:
ROOT
MainTop1
Topic1
Subtopic1
Subtopic2
MainTop2
Topic2
Subtopic1
JTree#setShowsRootHandles(boolean newValue) controls the state of the handles for root elements.
Normally, this is false. Try changing to true
The order of the factors affects the product:
Create all nodes
Create model
Add nodes to model
Create JTree
setRootVisible(false)
setModel()
simple example

How to detect and display desired message when clicked on DefaultMutableTreeNode in java?

I am tryin to make a software in which when clicked on the subnode of a jtree, detecting which node is selected, want to display respective message.
You will need to add a TreeSelectionListener to the model containing your nodes. The event arguments contain data for the node(s) selected.
Here is some example documentation.

Categories

Resources