java align an HBox to the bottom left - java

I dont want to use a gridpane.
So I have an HBox:
HBox fooBar = new HBox();
fooBar.setHeight(100);
fooBar.setWidth(100);
fooBar.setAlignment(pos.BOTTOM_LEFT);
I gave it a color in css.
I include it into my scene and for some reason the box stays stuck on the bottom left corner. Is there any way to position it?
I forgot to mention: this hbox is the child of another hbox where I didnt define any position or dimension.

Hbox is a component which determine position own children. If you want change position you should change alignment property in parent. It impact for all children. You couldn't change position for one child. All children have to be obedient.
You can use Pane for absolute positioning.

Related

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);

Add a Label inside the border of an HBox or a VBox

I would like to add a Label - i.e. some text inside the border of a JavaFX HBox. The text should sit in the top left corner of the HBox and be inside the visible border area. I used to be able to do this in Swing, but I haven't figured out how to do it in JavaFX.
Thanks

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.

Javafx HBox restrict to specific height

I have a HBox in my Javafx application with below configuration
HBox belowBox = new HBox(10);
belowBox.getStyleClass().addAll("pane", "vbox");
belowBox.setAlignment(Pos.CENTER);
belowBox.getChildren().addAll( .... );
belowBox.setMaxHeight(200);
belowBox.setPrefHeight(200);
belowBox.setFillHeight(false);
But still if I resize my application the HBox grows vertically. Is there a way to fix the height.
Thank you
But this is the exact behavior of the HBox layout pane. If you read the HBox documentation, you will see the following:
HBox lays out its children in a single horizontal row...
And also:
HBox will resize children (if resizable) to their preferred widths and uses its fillHeight property to determine whether to resize their heights to fill its own height or keep their heights to their preferred (fillHeight defaults to true)...
As said, if for some reason you set the fillHeight property from HBox, you can make the nodes contained within to fill the vacant vertical space, But this will only occur for the nodes that are resizable. For more information about using the JavaFX layout panels, look here. If I'm not mistaken, texts, geometric shapes and ImageView are not resizable objects.

Remove particular node in border pane in javafx

I have a border pane and there are components in its top, left and right side. I want to remove the components of its right side by using id of the borderPane through a mouse event. How do I do that?
Just do
borderPane.setRight(null);

Categories