How do you lock a button's position in JavaFX? - java

In one of my javafx projects I have a button that triggers the program. Upon displaying new data sometimes the button is pushed downwards due to other components of the borderpane expanding. Any way I can lock the button to a specific position so that it does not move if that occurs?

You could try placing the button on a separate Pane outside of the BorderPane, then grouping both Panes on a root Pane/main Pane of some sort, like so:
Any layout changes to child components of the BorderPane will not affect the layout of any components outside of it.
As you can see though, this leaves empty space at the top of the application. You can overlap the StackPane with the Button on top of the BorderPane if you fiddle with its layout settings, but this does mean that any child components of the BorderPane can be hidden behind the StackPane. It's up to you to decide which way you prefer.

Related

How to prevent pane overlapping in JavaFX

for my school project I am trying to make Classdiagrams graphical editor in JavaFX.
I have one rootpane (Pane) and by iterating through input parser I print graphical objects.
Every graphical object is child of Pane which holds elements (rect,text,line...) and that Pane with elements is child node of Rootpane (Pane). So Rootpane (Pane) has few childs of Pane.
Problem is, that after creating the Panes with graphical elements they do make some overlay around every Pane and I cannot drag other Panes.
I need to explicitly set Pane dimensions for example to be clipped by main Rectangle.
But this is not possible. Only way to do is make child nodes StackPane instead of Pane but my whole implementation now stands on absoulete positioning so It would be to rework whole project.
Does anyone know, by which command Can I set bounds to every Pane node not to overlay other nodes.
I would not make the elements a Pane. Instead I would use a Group node. And you can set a clipping path for every node (the group in your case), so I do not quite understand what your problem is.

JavaFX layout moves when button is clicked

This is a gif of my problem:
As you can see, the button resizes (elevates? and it moves it's outer layout with itself.
This is the hierarchy:
StackPane
Group // for other content
Group // The make hbox "wrap-content"
HBox // For the 2 buttons
JfxToggleButton // "This is test"
JfxButton // "Restart" button
The only code to add is that I am positioning the HBox's Group top right of the StackPane, like this:
StackPane.setAlignment(hboxGroup, Pos.TOP_RIGHT)
Only StackPane has this issue, BorderPane does not have it.
The reason I am using StackPane is because I want to have the controls on top of the main content.
ToggleButton and HBox have padding.
Actually, padding and alignment do not matter, since the HBox moves relatively regardless.
Btw, I am using jfonix library for button styling.
Thanks for your help.
Edit.:
For those who contribute this problem to JFoenix, this is the same with standard JavaFX controls: (the jump still occurs, only less noticable)
Compared to what I mentioned above, where theHboxhas it's place in the top of a BorderPane, the jump does not happen:
I realized AnchorPane does not have this problem.
So this the final layout hierarchy:
StackPane
Group // Content behind
AnchorPane // That restricts movement, keeps the buttons in place
Group // That keeps the background only around the buttons
HBox // Keeps the buttons next to each other
ToggleButton
Button
So I ended up with the problem that AnchorPane does not let clicks through. Which is fixed by setting the AnchorPane
anchorPane.setPickOnBounds(false);

JavaFX - setVisible hides the element but doesn't rearrange adjacent nodes

In JavaFX, if I have a scene with 2 VBox elements and each VBox has multiple Label in it.
If I set the top VBox to invisible, why does the bottom VBox not move up the scene where the top VBox was ?
The VBox is invisible but I would expect the other objects to move into its place.
I am using FXML to load my controls.
Node.setVisible(boolean) just toggles the visibility state of a Node.
To exclude a Node from its parents layout calculations you additionally have to set its managed state, by calling Node.setManaged(false).
If you want the managed state to be updated automatically alongside the visibility, you can use a binding as #jewelsea pointed out: node.managedProperty().bind(node.visibleProperty());
Since it's invisible, it wont move to the top. You have to remove it with something like:
// remove
vbox.getChildren().remove(...)
Once you've removed the element you want invisible then, the other element should move to the top.
Try to use setVisible and managedProperty together. Here is an example:
myHBox.setVisible(false);
myHBox.managedProperty().bind(myHBox.visibleProperty());
Instead of hiding the vbox you should remove it from the Children and if you want to show it again add the vbox again.
If l want to hide and unhide a node,
I resize the node to 0 if l want to hide it. That way, the node will not occupy space since is not visible to the user, so when l want it to be visible, l adjust the size again for it to be visible.

Preventing mouse from leaving Node?

I have a VBox that enters an edit mode if the user chooses to. How can I prevent the mouse from the leaving that VBox and clicking on other things?
Alternatively, how do I BLOCK OUT the rest of the application and make sure they aren't clickable? (Making them a lighter tint would show this too. Like how Adobe Illustrator enters a shape's edit mode).
Add a separate Pane to your layout and set its visibility to false and its style to something like -fx-background-color: #00000077. Add your VBox on top of that Pane (but not as a child of the Pane). Your layout should be something like this:
layout
-> controls
-> pane
-> vbox
Where layout is your main layout node, controls is your node containing most of your interface, pane is the dimming Pane, and vbox is the VBox you want to be emphasized. The children should be added in that order.
Whenever a node in vbox has focus, show pane (and hide it when focus is lost or your accept the user's input). pane, when visible, will prevent the user from interacting with other parts of your interface, specifically any node within layout (except vbox).

Use case of Glass Pane vs. Layered Pane

I've always been a little fuzzy on the difference between the glass pane and a layered pane. Is the glass pane essentially just "the very top layer of the root pane," or does it behave differently? When would you use a layered pane instead of the glass pane?
They are two different things:
the layered pane is the destination of all the contents that are added or shown inside a JFrame. For example, every normal component like JLabels, JTextFields, JTable etc.. in addition it implictly handles z-ordering of elements that are added to it so it can handles popup menus, or drag and drop effects: this because a popup menu is added to the layered pane with a z higher than the normal components, with the final effect to stay on top of other things. See here to understand the behaviour better.
the glass pane is an optional layer that is hidden by default and stays in any case on top of the layer pane. So basically everything you draw onto the glass pane will be always visible: you can think of it as a trasparent sheet that is applied on the top of a normal JFrame that you can choose to use you need special effects.
Both the layered pane and the glass pane are placed on the root pane that is the basis from which every frame is built up.

Categories