JavaFX not correctly setting up layout - css

I have been struggling with JavaFX for 2 days now, I have a scene I ought to display on my screen,but I have a problem, when I run the below code in SceneBuilder the code seems perfect everything seems in place, even with the Preview Window option it works but the moment I run my code an issue pops up, the stage seems to be 5+ more bigger in width than the scene, hence I get a layout which has a sort of white area on the right hand side, here is my code
the first Image is showing Layout Results when I run the code, the Asphalt layer is my scene, you can see the white layer on the far right end of my layout and down part but When tested in Scene Builder in the second Image all seems ok, my asphalt layer has filled up everything.
<AnchorPane minHeight="600.0" minWidth="1000.0"
xmlns="http://javafx.com/javafx/8.0.40"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainViewController">
<children>
<StackPane minHeight="600.0" minWidth="1000.0">
<children>
<BorderPane minHeight="600.0" minWidth="1000.0" style="-fx-background-color: #ecf0f1;">
</BorderPane>
</children>
</StackPane>
and my java Code for Inflating the fxml file
Stage primaryStage = new Stage();
primaryStage.setTitle("");
FXMLLoader loader = new FXMLLoader(getClass().getResource("/application/mainWindow.fxml"));
Region root = (Region) loader.load();
Scene scene = new Scene(root);
primaryStage.setTitle("");
primaryStage.setScene(scene);
primaryStage.setResizable(false);
primaryStage.centerOnScreen();
primaryStage.show();
primaryStage.setScene(scene);
primaryStage.toFront();
// Set minimum size based on client area's minimum sizes
// Set minimum size based on client area's minimum sizes
Stage loginStage = (Stage) (this.scene.getWindow());
primaryStage.setMinWidth(primaryStage.getWidth());
primaryStage.setMinHeight(primaryStage.getHeight());
primaryStage.show();
loginStage.close();

I don't see anything really wrong in this code, but setting the min size of the stage could be causing this problem, it's useless anyway because the stage uses the size of the scene. If this doesn't work try setting the max size for the Anchorpane or the size in the constructor of the scene in addition to the first solution.
(Btw, I wouldn't use Region for the root container, Parent or the container name are the more typical solutions)
Edit: Where's the code pf the controller? Does it do anything?

it seems the AnchorPane was the problem, I do not know why but after removing it and setting the child StackPane as parent all was sorted.

It's a bug for non-resizable stages on Windows -
see http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8089008

Related

Same distance from AnchorPane to AnchorPane

I created this GUI in Scene Builder. I have an AnchorPane on an AnchorPane, but how do I get it to the edge of the same distance? See second picture. Up, down, right, left should be the same distance from the red AnchorPane everywhere.
-So first thing you need to do, is to choose the layout you want to adjust (the blue one).
-Under the Inspecter panel on the right, you choose the "Layout" pane
-Finally you set the disired values under Anchor Pane Constraints. (they need to have all the same value)
You can ignore all the steps and edit your FXML file :
<AnchorPane layoutX="31.0" layoutY="14.0" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: blue;" AnchorPane.bottomAnchor="ENTER_THE_VALUE" AnchorPane.leftAnchor="ENTER_THE_VALUE" AnchorPane.rightAnchor="ENTER_THE_VALUE" AnchorPane.topAnchor="ENTER_THE_VALUE" />

How to make window fullscreen/maximized in Scene Builder?

I am making a view in SceneBuilder for my JavaFX application. I want my view to be maximized. How can I achieve this in SceneBuilder or the .fxml file?
You cannot do that using Scene Builder, since maximize or fullScreen are properties of the Stage and not the layouts set on the scene.
You can load and set the .fxml on the scene and later set the scene on the stage.
The following methods can be used on the stage :
setMaximized(boolean) - To maximize the stage and fill the screen.
setFullScreen(boolean) - To set stage as full-screen, undecorated window.
As you cannot maximize your view in fxml, you have to set the size of the stage to be maximized. There is no direct method for setting the size of the stage to be maximized in javafx 2 but there is another way you can do this. It is by manually setting the size of the stage. You can use this code:
Screen screen = Screen.getPrimary();
Rectangle2D bounds = screen.getVisualBounds();
primaryStage.setX(bounds.getMinX());
primaryStage.setY(bounds.getMinY());
primaryStage.setWidth(bounds.getWidth());
primaryStage.setHeight(bounds.getHeight());
This is the code that works for me
primaryStage.setMaximized(true);
it miximizes my window screen on the launch of the app.
I agree with Yemmy1000. primaryStage.setMaximized(true) works fine for me.
primaryStage.setScene(new Scene(root, 1800, 850));
primaryStage.setMaximized(true);
This code will go to width: 1800 and height:900 when restored down from maximum.
Two properties I found in stage which are useful.
First is setFullScreen(boolean) which will set your view to full screeb, but it will also hide all the taskbar and header of view.
Second is setMaximized(boolean) which will set you view to perfect like any other application view size.
I an using setMaximized(true) for my application.

On MacOS perfect => On Windows a grey bottom border

I hope anyone can help ... we have written a little application in JavaFX.
This module has a
VBOX ->
-ToolBar
-SplitPane ->
--AnchorPane
--AnchorPane
VBOX is set to 600px height. SplitPane and both AnchorPanes also.
In MacOS X everything looks great - but in Windows there is a big, grey border at the bottom.
I don't know which information I can give to solve this problem ...
Please ask me if you need anything to know.
I have tested the SplitPane and the VBOX with a red background. But => Fail, the border was still grey.
Thanks! And please forgive my english writing ... I'm not native :)
Mac :
Windows :
Your SplitPane is not able to cover the whole height of VBox. To force SplitPane to change its height when VBox changes its, use :
VBox.setVgrow(splitPane, Priority.ALWAYS);
In fxml you can achieve the same effect by adding :
<SplitPane VBox.vgrow="ALWAYS">

Resize FXML of a stage component on resizing scene

Please I have this problem i am trying to use
scene.getRoot().scaleXProperty().bind(scene.widthProperty().divide(dx));
scene.getRoot().scaleYProperty().bind(scene.heightProperty().divide(dy));
I have tried this code but at the exact size of the Parent, it stop resizing

How do you get a ScrollPane that is placed in the center of a BorderPane to work?

I have a program where i have a rootLayout made from a BorderPane. When i press a button in this rootLayout i place a new fxml view into the center of the the borderPane using .setCenter(). The view i am placing into the borderPane consists of an AnchorPane that has a scrollPane as it's child element and when i run this view by itself the scrolling works. However after placing the view into the borderPane it stops working. The area in the scrollPane doesnt move at all when i scroll down or up. I am guessing this has to do with the size that is given in the borderPane but the whole point of having the scrollPane is so that i can show all of the information in 1/3 of the space.
Any tips or Ideas on how to make this work in either javafx, fxml or scenebuilder?
Can't make comments yet ... correct me if I'm wrong but don't you have to use the AnchorPane as the child of the ScrollPane? I always have my TextAres as child of the ScrollPanes!

Resources