JavaFx: about nodes and scenes [duplicate] - javafx

This question already has an answer here:
How to bind Pane with another Pane in JavaFX
(1 answer)
Closed 3 years ago.
I have a problem with my project I have a stackpane that calls an fxml but my fxml gets bugged:
my fxml main:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="650.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.ControllerHome">
<children>
<VBox layoutX="10.0" layoutY="10.0" maxWidth="-Infinity" prefWidth="150.0" style="-fx-background-color: #150;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<HBox alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="80.0" prefWidth="150.0" style="-fx-background-color: #0fbcf9;">
<children>
<FontAwesomeIconView fill="WHITE" glyphName="HOME" size="30" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" style="-fx-font-family: Quicksand; -fx-font-weight: bold; -fx-fill: white;" text="Application">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Text>
</children>
<opaqueInsets>
<Insets />
</opaqueInsets>
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</padding>
</HBox>
<HBox alignment="CENTER_LEFT">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<VBox.margin>
<Insets top="40.0" />
</VBox.margin>
<children>
<FontAwesomeIconView fx:id="iconUser" glyphName="USERS" onMouseClicked="#xx" size="25" />
<Text fx:id="textUser" onMouseClicked="#xx" strokeType="OUTSIDE" strokeWidth="0.0" style="-fx-font-family: Quicksan; -fx-font-weight: bold; -fx-fill: #485460;" text="Usuarios">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Text>
</children>
</HBox>
<HBox alignment="CENTER_LEFT">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<children>
<FontAwesomeIconView glyphName="LIST" size="25" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" style="-fx-font-family: Quicksan; -fx-font-weight: bold; -fx-fill: #485460;" text="Requisições">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Text>
</children>
<VBox.margin>
<Insets top="10.0" />
</VBox.margin>
</HBox>
<VBox alignment="BOTTOM_CENTER" VBox.vgrow="ALWAYS">
<children>
<HBox alignment="CENTER_LEFT">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<children>
<FontAwesomeIconView glyphName="COG" size="25" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" style="-fx-font-family: Quicksan; -fx-font-weight: bold; -fx-fill: #485460;" text="Settings">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Text>
</children>
</HBox>
<HBox alignment="CENTER_LEFT">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<children>
<FontAwesomeIconView glyphName="SIGN_OUT" size="25" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" style="-fx-font-family: Quicksan; -fx-font-weight: bold; -fx-fill: #485460;" text="Logout">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Text>
</children>
</HBox>
</children>
<VBox.margin>
<Insets />
</VBox.margin>
<padding>
<Insets bottom="20.0" />
</padding>
</VBox>
</children>
</VBox>
<HBox fx:id="subRoot" maxHeight="-Infinity" prefHeight="80.0" style="-fx-background-color: #000;" AnchorPane.leftAnchor="150.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
<StackPane fx:id="mainRoot" layoutX="265.0" layoutY="256.0" prefHeight="150.0" prefWidth="200.0" style="-fx-background-color: #fff;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="150.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="80.0" />
</children>
</AnchorPane>
my controller:
public class ControllerHome implements Initializable {
#FXML
private HBox subRoot;
#FXML
private FontAwesomeIconView iconUser;
#FXML
private Text textUser;
#FXML
private StackPane mainRoot;
#FXML
void xx(MouseEvent event) throws IOException {
System.out.println("xd");
Pane content = FXMLLoader.load(getClass().getResource("mainContentUser.fxml"));
mainRoot.getChildren().addAll(content);
}
#Override
public void initialize(URL location, ResourceBundle resources) {
/*
iconUser.addEventHandler(MouseEvent.MOUSE_CLICKED, (e) -> {
System.out.println("xd");
});
textUser.addEventHandler(MouseEvent.MOUSE_CLICKED, (e) -> {
System.out.println("xd");
});*/
try {
HBox menu = FXMLLoader.load(getClass().getResource("menuUser.fxml"));
subRoot.getChildren().addAll(menu);
System.out.println("xdxx");
} catch (IOException ex) {
Logger.getLogger(ControllerHome.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
my fxml with anchor Pane:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="559.0" prefWidth="811.0" style="-fx-background-color: #f547;" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Button layoutX="388.0" layoutY="199.0" mnemonicParsing="false" text="Button" />
</children>
</AnchorPane>
I don't know what is going on it is not full size and is covering other parts of my screen
I don't know if it's because of the stackpane or some configuration I made.
If anyone can help me on how I can solve this

Your main problem is misusing different Pane types to achive your goal. It would be very hard to point out all the problems this layout has. That is why I publish fxml which provides expected layout. Load it in SceneBuilder and try to manipulate it for better understanding. Remember that order of addition to GridPane (same for every Pane) affects z-order of children.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.171">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="-Infinity" minWidth="10.0" prefWidth="200.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="-Infinity" minHeight="-Infinity" prefHeight="100.0" vgrow="ALWAYS" />
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="-Infinity" prefHeight="200.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<VBox style="-fx-background-color: green;" GridPane.rowIndex="1">
<children>
<VBox VBox.vgrow="ALWAYS">
<children>
<Button mnemonicParsing="false" text="Button" />
<Button mnemonicParsing="false" text="Button" />
</children>
</VBox>
<VBox alignment="BOTTOM_LEFT" VBox.vgrow="ALWAYS">
<children>
<Button mnemonicParsing="false" text="Button" />
<Button mnemonicParsing="false" text="Button" />
</children>
</VBox>
</children>
</VBox>
<StackPane prefHeight="150.0" prefWidth="200.0" style="-fx-background-color: pink;" GridPane.columnIndex="1" GridPane.rowIndex="1">
<children>
<Button mnemonicParsing="false" text="Button" />
</children>
</StackPane>
<HBox alignment="CENTER_LEFT" spacing="16.0" style="-fx-background-color: black;" GridPane.columnIndex="1">
<children>
<Button mnemonicParsing="false" text="Button" />
<Button mnemonicParsing="false" text="Button" />
<Button mnemonicParsing="false" text="Button" />
</children>
<padding>
<Insets left="16.0" />
</padding>
</HBox>
<StackPane style="-fx-background-color: lightblue;" />
</children>
</GridPane>

Related

Changes in the fxml file are not visible

Basically when i update my .fxml file, i can't see the new stuff...it's like showing the old version of the .fxml...with the old stuff... and yes i save the file...
This is my Main.java
package Library.Assistant.Ui.Main;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class MainLoader extends Application {
public static void main(String arg[]) {
launch(arg);
}
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Main.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
This is my Main.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXTextField?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="548.0" prefWidth="617.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Library.Assistant.Ui.Main.MainController">
<children>
<MenuBar maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Delete" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
<GridPane fx:id="grid" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" VBox.vgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<TabPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" tabClosingPolicy="UNAVAILABLE" GridPane.rowSpan="2147483647">
<tabs>
<Tab text="Book Issue">
<content>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0">
<children>
<HBox alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" VBox.vgrow="ALWAYS">
<children>
<TextField fx:id="enterBookID" promptText="Enter Book ID" />
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" HBox.hgrow="ALWAYS">
<children>
<Label text="Book Name" />
<Label text="Author" />
</children>
</VBox>
</children>
</HBox>
<HBox alignment="CENTER" layoutX="10.0" layoutY="10.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" VBox.vgrow="ALWAYS">
<children>
<TextField promptText="Enter Member ID" />
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" HBox.hgrow="ALWAYS">
<children>
<Label text="Member Name" />
<Label text="Contact" />
</children>
</VBox>
</children>
</HBox>
<HBox alignment="CENTER" layoutX="10.0" layoutY="404.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" VBox.vgrow="ALWAYS">
<children>
<JFXButton maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Issue" HBox.hgrow="ALWAYS" />
</children>
</HBox>
</children>
</VBox>
</content>
</Tab>
<Tab text="Renew / Submission">
<content>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
<children>
<BorderPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" VBox.vgrow="ALWAYS">
<top>
<JFXTextField alignment="CENTER" promptText="Enter Book ID" BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets bottom="20.0" left="10.0" right="10.0" top="10.0" />
</BorderPane.margin>
</JFXTextField>
</top>
<center>
<ListView maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" BorderPane.alignment="CENTER" />
</center>
<bottom>
<HBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" BorderPane.alignment="CENTER">
<children>
<JFXButton maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Renew" HBox.hgrow="ALWAYS" />
<JFXButton maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Submission" HBox.hgrow="ALWAYS" />
</children>
<BorderPane.margin>
<Insets />
</BorderPane.margin>
</HBox>
</bottom>
</BorderPane>
</children>
</VBox>
</content>
</Tab>
</tabs>
</TabPane>
<Button contentDisplay="TOP" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Add Member" GridPane.columnIndex="1">
<graphic>
<ImageView fitHeight="50.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#add_mem.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button contentDisplay="TOP" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Add Book" GridPane.columnIndex="1" GridPane.rowIndex="1">
<graphic>
<ImageView fitHeight="50.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#add_book.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button contentDisplay="TOP" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="View Members" GridPane.columnIndex="1" GridPane.rowIndex="2">
<graphic>
<ImageView fitHeight="50.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#list_mem.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button contentDisplay="TOP" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="View Books" GridPane.columnIndex="1" GridPane.rowIndex="3">
<graphic>
<ImageView fitHeight="50.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#list_book.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button contentDisplay="TOP" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Settings" GridPane.columnIndex="1" GridPane.rowIndex="4">
<graphic>
<ImageView fitHeight="50.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#settings.png" />
</image>
</ImageView>
</graphic>
</Button>
</children>
</GridPane>
</children>
</VBox>
I just can't understand why it's showing the old version of the file...yesterday everything was working fine.I was adding new stuff and it was showing them properly, but today it keeps showing the version from yesterday...no matter how many stuff i change..

Can i resize scene with the size of window JavaFx without binding each widget?

In my application, I am switching fxml files for changing the views because I don't properly know the concepts of Scene and Parent roots. all of my fxml files have an AnchorPane(600,400). This is how my start method looks like.
#Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("loginpage.fxml"));
primaryStage.setTitle("Eye Ratina Scanner");
primaryStage.setScene(new Scene(root, 600, 400));
primaryStage.show();
}
this is how I am changing views.
AnchorPane pane = FXMLLoader.load(getClass().getResource("../loginpage.fxml"));
dashpane.getChildren().setAll(pane) //dashpane is AnchorPane
I made the whole app in size of 600:400. Now I want that when I click on the window maximize button, all of the components resize larger and preserve the ratio. two images are attached below to show what's happening.when i click on maximize
normal 600:400 view
now I don't want to bind each button, imageview, anchorpane, text fields, labels, and so on. It will take too long since I have around 42 fxml files. Can we achieve our results by a single snippet? I didn't find any other post having exactly the same issue.
thanks for answering in advance. I totally appreciate your help.
Here is a sample layout. It uses a VBox as the root. It uses an AnchorPane. Inside the AnchorPane is a GridPane. You will still need to do work to make the ImageView and Label text grow as the Stage gets bigger.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Circle?>
<?import javafx.scene.text.Font?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: lightblue;" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<HBox maxHeight="400.0" prefHeight="75.0" VBox.vgrow="SOMETIMES">
<children>
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Dashboard" HBox.hgrow="ALWAYS">
<font>
<Font name="System Bold" size="19.0" />
</font>
</Label>
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Analytics" HBox.hgrow="ALWAYS">
<font>
<Font name="System Bold" size="19.0" />
</font>
</Label>
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Settings" HBox.hgrow="ALWAYS">
<font>
<Font name="System Bold" size="19.0" />
</font>
</Label>
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Notifications" HBox.hgrow="ALWAYS">
<font>
<Font name="System Bold" size="19.0" />
</font>
</Label>
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Logout" HBox.hgrow="ALWAYS">
<font>
<Font name="System Bold" size="19.0" />
</font>
</Label>
</children>
</HBox>
<AnchorPane prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: grey;" VBox.vgrow="ALWAYS">
<children>
<GridPane hgap="20.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" vgap="20.0" AnchorPane.bottomAnchor="20.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="20.0">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
</rowConstraints>
<children>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: white;">
<children>
<Circle fill="DODGERBLUE" radius="25.0" stroke="BLACK" strokeType="INSIDE" VBox.vgrow="ALWAYS" />
<Label text="Label" />
<Label text="Label" />
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: white;" GridPane.columnIndex="1">
<children>
<Circle fill="DODGERBLUE" radius="25.0" stroke="BLACK" strokeType="INSIDE" />
<Label text="Label" />
<Label text="Label" />
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: white;" GridPane.columnIndex="3" GridPane.rowIndex="1">
<children>
<Circle fill="DODGERBLUE" radius="40.0" stroke="BLACK" strokeType="INSIDE" />
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: white;" GridPane.columnIndex="2" GridPane.rowIndex="1">
<children>
<Circle fill="DODGERBLUE" radius="25.0" stroke="BLACK" strokeType="INSIDE" />
<Label text="Label" />
<Label text="Label" />
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: white;" GridPane.columnIndex="1" GridPane.rowIndex="1">
<children>
<Circle fill="DODGERBLUE" radius="25.0" stroke="BLACK" strokeType="INSIDE" />
<Label text="Label" />
<Label text="Label" />
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: white;" GridPane.rowIndex="1">
<children>
<Circle fill="DODGERBLUE" radius="25.0" stroke="BLACK" strokeType="INSIDE" />
<Label text="Label" />
<Label text="Label" />
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: white;" GridPane.columnIndex="3">
<children>
<Circle fill="DODGERBLUE" radius="25.0" stroke="BLACK" strokeType="INSIDE" />
<Label text="Label" />
<Label text="Label" />
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: white;" GridPane.columnIndex="2">
<children>
<Circle fill="DODGERBLUE" radius="25.0" stroke="BLACK" strokeType="INSIDE" />
<Label text="Label" />
<Label text="Label" />
</children>
</VBox>
</children>
</GridPane>
</children>
</AnchorPane>
</children>
</VBox>

cannot place button on bottom right corner

In scene builder preview button is on exact spot i.e bottom right corner without any gap but when i run my application there is gap.
Button is on a pane and pane is placed on top of anchor pane.
How can i fix this issue?
same thing happening with other components when i placed them on far right or far bottom.
Please examin the sample. Pay attention to min_width, min_height, pref_width, pref_height, max_width, max_height, vgrow, hgrow attributues in SceneBuiler.
The main concept is that type of pane you use sholud give you desired layout. It should not be hardcoded.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<HBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<children>
<VBox style="-fx-background-color: yellow;">
<children>
<StackPane VBox.vgrow="ALWAYS">
<children>
<Button mnemonicParsing="false" text="Menu Button" />
</children>
</StackPane>
<StackPane VBox.vgrow="ALWAYS">
<children>
<Button mnemonicParsing="false" text="Menu Button" />
</children>
</StackPane>
<StackPane layoutX="10.0" layoutY="210.0" VBox.vgrow="ALWAYS">
<children>
<Button mnemonicParsing="false" text="Menu Button" />
</children>
</StackPane>
<StackPane layoutX="10.0" layoutY="276.0" VBox.vgrow="ALWAYS">
<children>
<Button mnemonicParsing="false" text="Menu Button" />
</children>
<VBox.margin>
<Insets />
</VBox.margin>
</StackPane>
<StackPane layoutX="10.0" layoutY="310.0" VBox.vgrow="ALWAYS">
<children>
<Button mnemonicParsing="false" text="Menu Button" />
</children>
</StackPane>
</children>
</VBox>
<VBox style="-fx-background-color: red;" HBox.hgrow="ALWAYS">
<children>
<StackPane prefHeight="150.0" prefWidth="200.0" style="-fx-background-color: green;" VBox.vgrow="ALWAYS">
<children>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" style="-fx-background-color: purple;">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Label" />
<TextField GridPane.columnIndex="1" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label text="Label" GridPane.rowIndex="1" />
<Label text="Label" GridPane.rowIndex="2" />
</children>
</GridPane>
</children>
</StackPane>
<HBox alignment="TOP_RIGHT">
<children>
<Button mnemonicParsing="false" text="Button" />
</children>
</HBox>
</children>
</VBox>
</children>
</HBox>
Have you put constraints in the layout section of the button? It could be related to that. Check layout x and layout of the button and the pref size x and y of AnchorPane, if that is same, the button must be on the left-bottom corner of the pane.

No content in table scroll-bar should come

When I am having data in the tableview (which is custom component), then horizontal scrollbar is visible, but if there will no data and only columns are there then scroll-bar is not visible.
Is it because of custom component I made or my FXML needs some changes.
FXML
<AnchorPane stylesheets="prj.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<VBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" >
<children>
<ScrollPane fitToHeight="true" fitToWidth="true" VBox.vgrow="ALWAYS">
<content>
<prjTableView minWidth="500.0" maxWidth="500.0" prefWidth="500.0" VBox.vgrow="ALWAYS" fx:id="treeTableView" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<styleClass>
<String fx:value="k-table-view" />
<String fx:value="redBorder" />
</styleClass>
</prjTreeTableView>
</content>
</ScrollPane>
<HBox alignment="BASELINE_LEFT">
<children>
<HBox>
<children>
<Label text="Page Size">
<HBox.margin>
<Insets left="2.0" top="5.0" />
</HBox.margin>
</Label>
<TextField fx:id="itemsPerPage" maxWidth="-Infinity"
minWidth="-Infinity" prefHeight="22.0" prefWidth="40.0" text="50">
<HBox.margin>
<Insets left="8.0" top="6.0" />
</HBox.margin>
<tooltip>
<Tooltip text="Enter desired page number" />
</tooltip>
</TextField>
<Pagination fx:id="pagination" maxWidth="-Infinity"
minWidth="-Infinity" prefHeight="42.0" prefWidth="235.0"
translateX="1.0" translateY="1.0">
<HBox.margin>
<Insets />
</HBox.margin>
</Pagination>
<Label fx:id="displayInfo">
<HBox.margin>
<Insets top="5.0" />
</HBox.margin>
</Label>
</children>
</HBox>
</children>
</HBox>
</children>
</VBox>
</children>
</AnchorPane>

How to distribute multiple HBoxes equally in length so that they have equal spans from one side of a scene to the other

I have HBoxes nested in one HBox that spans from one side of the window to another. What I want is the length of those four HBoxes to be distributed equally so that they have the same span whenever the window is resized!
My code snippet:
<HBox prefHeight="150.0" prefWidth="200.0">
<children>
<HBox>
<children>
<Pane prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #abb7b7;" />
</children>
<padding>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</padding>
</HBox>
<HBox>
<children>
<Pane prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #6c7a89;" />
</children>
<padding>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</padding>
</HBox>
<HBox>
<children>
<Pane prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #008080;" />
</children>
<padding>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</padding>
</HBox>
</children>
</HBox>
Use the hgrow property on each of the 'child' HBoxes:
<HBox prefHeight="150" prefWidth="200">
<HBox HBox.hgrow="ALWAYS">
<!-- ... -->
</HBox>
<HBox HBox.hgrow="ALWAYS">
<!-- ... -->
</HBox>
<!-- ... -->
</HBox>

Resources