JavaFX layout moves when button is clicked - java

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

Related

How to prevent autoscroll in SrollPane in javafx

I'm working on a javafx project that has a VBox inside a ScrollPane. The problem is that when the height of the vBox decreases, the scrollPane scrolls Up Automatically. How can i prevent that ? Knowing that it does not scrolls when the height increases!
Note: inside the vBox i have buttons which add/remove some TextFields which result in the increasing/decreasing of the VBox height.
I cannot show the whole code due to work regulations but here is where i define and add the VBox inside ScrollPane:
VBox mainVBox = new VBox();
mainVBox.setStyle("-fx-background-color: #0292b7");
mainVBox.setPrefWidth(400);
mainVBox.setSpacing(10);
mainVBox.setPadding(new Insets(3,5,3,5));
ScrollPane scrollPane = new ScrollPane();
scrollPane.setContent(mainVBox);
scrollPane.setPrefWidth(420);
scrollPane.setPrefHeight(600);
VBox.setVgrow(scrollPane,Priority.ALWAYS);
The reason of this behavior is that you remove the element which currently has the focus. Which lead to a focus-transfer to the first element in the container and the ScrollPane automatically scrolls to this element.
To change this you can add for example mainVBox.requestFocus(); in you code before you remove the Button or/and TextField.

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

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.

java align an HBox to the bottom left

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.

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

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

Categories