Hide some elements without occupying space in javaFx - java

Can anyone tell me is there any display:none property in JavaFX like in Css?
Actually I want to hide some labels and don't want them to occupy space when hidden.
How can I achieve this in JavaFX?
TIA

Nodes are considered for layout purposes by parents as long as their managed property is true. For this reason you need to set both the visible and the managed property:
node.setVisible(false);
node.setManaged(false);
This is an alternative to simply removing the node from it's parent that allows you to make the node reappear again. If you don't want do anything with the node after hiding it, you should simply remove it from the scene instead:
parentLayout.getChildren().remove(node);

Related

How to set multiple window owners in javafx?

I know it's probably not possible, but that is the best way to describe the resulting effect. I need to make a window always on top of a certain set of other windows, much in the same way that a child window will always stay on top of its parent. The thing is, now I want to have multiple "parents". How do I do that? I know it's possible since the GIMP application does it with its toolbox.

How to achieve absolute positioning in Javafx (FXML)

Ok lets just assume I wanted to have the following layout:
<GridPane>
<Button></Button>
<Button></Button>
<GridPane/>
<HBox>
<Label></Label>
<HBox/>
Now, in HTML I would simply apply position: absolute via css and one of the two containers would detache from the normal document flow allowing it to float around without pushing its siblings aside. I am trying to achieve something similar but im on it for hours already.
According to the Oracle documentation this can be achieved with either StackPane, which I dont want because I want the other container unaffected) or I could use a raw Pane node which somehow acts crazy because well, its a base class. The documentation about the pane also says:
This class may be used directly in cases where absolute positioning of children
and well of children doesnt sound good...as in my case it has to be the direct container.
So my question is: how can I achieve absolute positioning without hacking around with too much math?
Could localToScene() be what I want?
Transforms a bounds from the local coordinate space of this Node into the coordinate space of its scene.
My impression is that you are still thinking in HTML-terms and not JavaFX-Terms. For example in JavaFX there is no "normal document flow". Everything has to be put into some layout container and this container determines how things are layed out and there is nothing wrong with using a Pane directly if you have to. Although I am not sure what your actual use-case is, I think you might want to have a look at the AnchorPane.

JTree representing a graph

I am using the JTree Swing utility to represent a Tree that actually have loops. I have a single node called root, but some of the children will eventually point back to other parts of the tree, thus not making it a true tree, but rather a graph.
My Java application keeps locking up, (no exceptions being thrown, no stack overflow... etc) when I try to use the little gray arrows to expand and contract parts of the graph.
My question is, does JTree require that none of the DefaulMutableTreeNodes not contain a loop?
If so, how do we represent something like that using a JTree utility. For example, when you are debugging an application say in eclipse, and you can infinitely use the variable tree in debug mode to keep on looking through a looped object. That is the behavior I am looking for.
Any suggestions?
I don't think it's a problem that nodes in a Jtree loop on themselves. Apparently you have a problem only with an "expand all" button, which makes sense because an expand all method will go recursively through the nodes until they have no sons.
Jtree does not have an expand all button by default, so I'm guessing yours is already customized...? My suggestion would be either remove the button, or customize the code to stop the expansion if findind a node that was already expanded higher in the hierarchy.

How do I determine if a JDialog has children?

I've got a custom window class that is a couple levels down extending a JDialog. We have windows that we create and sometimes we create new windows as children of existing windows using the constructor that takes a parent argument.
I need to put some code somewhere in our custom class that does something different depending on whether not the window has children. I know of getParent(), etc, and I can see that I can loop through the components of the window, but for the life of me, I can't seem to figure out how to determine whether or not my current window has any child windows.
Is there a way to do this? Any help is, as always, much appreciated.
See Window.getOwnedWindows().
will getOwnedWindows() do? It belongs to java.awt.Window which in JDialog's parent lineage.

Is there a way to have expander icons for multiple roots in a JTree?

I have a JTree with multiple "roots" (Of course, I actually have an invisible real root with multiple children).
The nodes expand and collapse on double click, but there's no visual indication that you can do this as there is no expander icon.
This is made worse by the fact that the tree is collapsed by default, but expanding the "roots" doesn't really help, as each has many children and it would look cluttered.
Is there a way to display the expander icons without making the real (and utterly valueless) root visible?
Any other suggestions to make the display clearer welcome.
Would tree.setShowsRootHandles(true) be a good way to display those "expander icons" ?
A tree typically also performs some look-and-feel-specific painting to indicate relationships between nodes. You can customize this painting in a limited way.
First, you can use tree.setRootVisible(true) to show the root node or tree.setRootVisible(false) to hide it.
Second, you can use tree.setShowsRootHandles(true) to request that a tree's top-level nodes — the root node (if it is visible) or its children (if not) — have handles that let them be expanded or collapsed.
Check also your look and feel to be sure what the renderer does with your tree.

Categories