Why when I shrink my splitPane a grey area appears? - javafx

I have a problem with my fxml interface.
When I try to reduce a specific part of my application, a grey area covers it.
An example in image will be more speaking:
I've tried quite a few things (by modifying parameters of the different components) but the white zone is still there.
Do you have any idea what my problem is?
The code (example):
MainApp.java
public class MainApp extends Application {
#Override
public void start(Stage primaryStage) {
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource("view/test.fxml"));
AnchorPane root = (AnchorPane) loader.load();
Controller controller = loader.getController();
controller.setMainApp(this);
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
Controller.java
public class Controller implements Initializable{
MainApp mainApp;
#FXML
Label label;
#Override
public void initialize(URL location, ResourceBundle resources) {
label.setText("Hello");
}
public void setMainApp(MainApp mainApp) {
this.mainApp = mainApp;
}
}
test.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane id="AnchorPane"
maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
minHeight="250.0" minWidth="400.0" prefHeight="519.0" prefWidth="921.0"
xmlns="http://javafx.com/javafx/8.0.111"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="application.view.Controller">
<children>
<SplitPane dividerPositions="0.49439102564102566"
maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
prefHeight="799.0" prefWidth="1250.0" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="400.0" minWidth="400.0"
prefHeight="511.0" prefWidth="467.0" rotate="0.0" />
<AnchorPane minHeight="0.0" minWidth="0.0"
prefHeight="797.0" prefWidth="349.0">
<children>
<SplitPane layoutX="17.0" layoutY="7.0"
orientation="VERTICAL" prefHeight="797.0" prefWidth="346.0"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" minHeight="108.0"
minWidth="447.0" prefHeight="108.0" prefWidth="447.0">
<children>
<SplitPane dividerPositions="0.5248796147672552"
maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" minHeight="-Infinity"
minWidth="-Infinity" prefHeight="112.0" prefWidth="442.0"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" minHeight="0.0"
minWidth="0.0" prefHeight="110.0" prefWidth="313.0" />
<AnchorPane maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" minHeight="0.0"
minWidth="0.0" prefHeight="110.0" prefWidth="87.0">
<children>
<Label fx:id="label" layoutX="52.0" layoutY="223.0"
prefHeight="16.0" prefWidth="96.0" text="Test !">
<font>
<Font size="29.0" />
</font>
</Label>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
Note: I made this interface with the help of Gluon's SceneBuilder.
Thank you in advance.

In SceneBuilder if I click on the root SplitPane and slide it's divider to the right, I get this picture below. This means that at some point your min values on the highlighted AnchorPane is greater than it's parent's current width.
I basically set most of the later AnchorPanes' preferred width to USE_COMPUTER_SIZE and the highlighted AnchorPane's min width to USE_PRE_SIZE and it's preferred width to USE_COMPUTER_SIZE. Here is the code I used to fix the problem:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane id="AnchorPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="250.0" minWidth="400.0" prefHeight="519.0" prefWidth="921.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.view.Controller">
<children>
<SplitPane dividerPositions="0.49836779107725787" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="799.0" prefWidth="1250.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="400.0" minWidth="400.0" prefHeight="511.0" prefWidth="467.0" rotate="0.0" />
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="797.0" prefWidth="349.0">
<children>
<SplitPane layoutX="17.0" layoutY="7.0" orientation="VERTICAL" prefHeight="797.0" prefWidth="346.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane>
<children>
<SplitPane dividerPositions="0.5248796147672552" minHeight="-Infinity" minWidth="-Infinity" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" />
<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" prefHeight="110.0" prefWidth="87.0">
<children>
<Label fx:id="label" layoutX="52.0" layoutY="223.0" prefHeight="16.0" prefWidth="96.0" text="Test !">
<font>
<Font size="29.0" />
</font>
</Label>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>

Related

How to automatically resize JavaFX containers when window is maximized?

Basically, I have the following document:
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXTabPane?>
<?import com.jfoenix.controls.JFXTreeView?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="566.0" prefWidth="753.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gui.controller">
<center>
<JFXTabPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" BorderPane.alignment="CENTER">
<tabs>
<Tab text="TAB">
<content>
<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="495.0" prefWidth="753.0">
<children>
<StackPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="150.0" prefWidth="200.0" VBox.vgrow="ALWAYS">
<children>
<HBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" nodeOrientation="LEFT_TO_RIGHT" prefHeight="100.0" prefWidth="200.0">
<children>
<JFXTreeView fx:id="treeView" />
<TableView maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="277.0" prefWidth="753.0">
<columns>
<TableColumn maxWidth="-1.0" text="COL" />
<TableColumn text="COL" />
<TableColumn text="COL" />
<TableColumn text="COL" />
<TableColumn minWidth="0.0" text="COL" />
<TableColumn text="COL" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
</children>
</HBox>
</children>
</StackPane>
</children>
</VBox>
</children>
</AnchorPane>
</content>
</Tab>
</tabs>
</JFXTabPane>
</center>
</BorderPane>
The main class to load the FXML document:
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
BorderPane parent = (BorderPane) FXMLLoader.load(getClass().getResource("document.fxml"));
Scene scene = new Scene(parent);
primaryStage.setScene(scene);
primaryStage.show();
}
}
When i maximize the window, the table and the rest of the containers don't resize accordingly. I tried to set Max Width and Max Height for all the containers to MAX_VALUE in SceneBuilder but nothing really happens.
Is there a way to automatically expand the containers so that they can use all the space when the window is maximized ?
After spending some time investigating the problem. The steps that have corrected the issue are :
1- Setting all the anchor pane constraints to 0 (In the VBox tag) will allow for the child container to occupy all the space provided by the parent.
<VBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
2- Setting the Hgrow attribute of the TabeView to Always will allow for the table to grow horizontally whenever it finds space.
3- For the rest of the containers, keeping the default settings and setting Max Height and Max Width to USE_COMPUTED_SIZE will do the trick.
Here is a start: a border pane that will grow with scene:
public void start(Stage stage) {
BorderPane root = new BorderPane();
root.setStyle("-fx-background-color: yellow");
root.setCenter(new Text("center"));
root.setTop(new Text("top"));
root.setBottom(new Text("bottom"));
Scene scene = new Scene(root);
root.prefHeightProperty().bind(scene.heightProperty());
root.prefWidthProperty().bind(scene.widthProperty());
stage.setScene(scene);
stage.show();
}

overlapping of button when size of window increases - javafx - fxml

I have an issue with buttons size. When I increase the size of my window,
The buttons overlap each other. I have tried many thnigs to avoid that, for example wrap each button in an anchorpane, without success.
Here is the fxml code used for the button "devis" for example:
<AnchorPane layoutX="5.0" layoutY="71.0" maxHeight="61.25" prefHeight="58.0" prefWidth="206.0" AnchorPane.bottomAnchor="116.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="71.0">
<children>
<Button fx:id="devis" maxHeight="65.0" mnemonicParsing="false" onAction="#selectViewDevis" prefHeight="65.0" prefWidth="206.0" text="Devis" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<font>
<Font size="14.0" />
</font>
</Button>
</children>
</AnchorPane>
The 2 images of my window before and after increasing
Before increasing
After increasing
Thanks for your help,
Aaron
Try using a 'VBox'.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1">
<children>
<SplitPane dividerPositions="0.35451505016722407" layoutX="189.0" layoutY="167.0" prefHeight="160.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<VBox layoutX="24.0" layoutY="14.0" minWidth="200.0" prefHeight="200.0" prefWidth="100.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<StackPane prefHeight="150.0" prefWidth="200.0">
<children>
<ImageView fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" />
</children>
</StackPane>
<Button maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Button" />
<Button maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Button" />
<Button maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Button" />
</children>
</VBox>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
</items>
</SplitPane>
</children>
</AnchorPane>

JavaFX Scene Builder crash

I have some problem with screen builder.
For some fxml it creash after load. I wwas trying many time to run it, but it block, and I must kill process.
The fxml is OK, the content is correctly displaying in my application. Here is the example of my FXML that cause crash of scene builder.
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXTabPane?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import java.lang.String?>
<?import java.net.URL?>
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" id="mainApplicationWindow" fx:id="mainApplicationWindow"
styleClass="mainAnchorPane, gt-screen" xmlns="http://javafx.com/javafx/8.0.112-ea"
fx:controller="com.genealogytree.client.desktop.controllers.implementation.PaneMainApplicationWindowController">
<stylesheets>
<URL value="#/layout/style/gentree.css"/>
</stylesheets>
<children>
<SplitPane dividerPositions="0.2809364548494983" layoutX="139.0" layoutY="78.0" orientation="VERTICAL"
prefHeight="200.0" prefWidth="160.0" styleClass="gt-splitpane" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane maxHeight="220.0" minHeight="220.0" prefHeight="220.0">
<children>
<JFXTabPane fx:id="gtMainTabPane" AnchorPane.bottomAnchor="10" AnchorPane.leftAnchor="20"
AnchorPane.rightAnchor="20" AnchorPane.topAnchor="10">
<tabs>
</tabs>
</JFXTabPane>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
<children>
<SplitPane dividerPositions="0.22690763052208834" layoutX="55.0" layoutY="46.0"
prefHeight="160.0" prefWidth="200.0" styleClass="gt-splitpane"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane id="splitPaneHorizontal" maxWidth="250.0" minWidth="250.0"
prefWidth="250.0">
<children>
<TableView fx:id="gtFamilyMemberTable" layoutX="20.0" layoutY="12.0"
onMouseClicked="#showInfoMember" prefHeight="200.0" prefWidth="200.0"
AnchorPane.bottomAnchor="50.0" AnchorPane.leftAnchor="10.0"
AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="5.0">
<columns>
<TableColumn fx:id="simNameColumn" maxWidth="110.0" minWidth="110.0"
prefWidth="-1.0" text="%simName"/>
<TableColumn fx:id="simSurnameColumn" maxWidth="110.0" minWidth="110.0"
prefWidth="-1.0" text="%simSurname"/>
</columns>
<styleClass>
<String fx:value="firstTypeTable"/>
<String fx:value="tableMembersAndRelations"/>
</styleClass>
</TableView>
<TableView id="gtFamilyRelationTable" fx:id="gtFamilyRelationTable"
layoutX="20.0" layoutY="12.0" onMouseClicked="#showInfoRelation"
prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="50.0"
AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0"
AnchorPane.topAnchor="5.0">
<columns>
<TableColumn fx:id="relationSimLeftColumn" maxWidth="85.0"
minWidth="85.0" prefWidth="-1.0" text="%relation_sim"/>
<TableColumn fx:id="relationTypeColumn" maxWidth="50.0" minWidth="50.0"
prefWidth="-1.0" text="%relation_type"/>
<TableColumn fx:id="relationSimRightColumn" maxWidth="85.0"
minWidth="85.0" prefWidth="-1.0" text="%relation_sim"/>
</columns>
<styleClass>
<String fx:value="firstTypeTable"/>
<String fx:value="tableMembersAndRelations"/>
</styleClass>
</TableView>
<AnchorPane id="anchorToogleButtons" prefHeight="25.0"
AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="10"
AnchorPane.rightAnchor="10.0">
<ToggleButton id="buttonShowMemberTable" fx:id="buttonShowMemberTable"
layoutX="23.0" mnemonicParsing="false"
prefWidth="114.0" styleClass="toogleButtonShowTable"
text="Members" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0"/>
<ToggleButton id="buttonShowRelationTable" fx:id="buttonShowRelationTable"
layoutX="125.0" layoutY="12.0" mnemonicParsing="false"
prefWidth="114.0"
styleClass="toogleButtonShowTable" text="Relations"
AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0"/>
</AnchorPane>
</children>
</AnchorPane>
<AnchorPane fx:id="workAnchorPane">
<children>
<AnchorPane fx:id="workAnchorPaneContent" AnchorPane.bottomAnchor="50.0"
AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="20.0"
AnchorPane.topAnchor="5.0">
</AnchorPane>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
Try opening SceneBuilder as an administrator first before opening the file up in your IDE. Not sure why this works but it got me up and running.

Why JavaFX blurs controls and how to fix it?

I have this simple form of JavaFX application with two TextArea without style properties:
When viewing the form I see this:
FXML code here:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<TitledPane animated="false" prefWidth="300.0" text="untitled" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<content>
<TextArea prefHeight="200.0" prefWidth="200.0" />
</content>
</TitledPane>
<SplitPane dividerPositions="0.5" orientation="VERTICAL" prefHeight="200.0" prefWidth="160.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="300.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
<children>
<TitledPane animated="false" text="untitled" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<TextArea prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="-10.0" AnchorPane.leftAnchor="-10.0" AnchorPane.rightAnchor="-10.0" AnchorPane.topAnchor="-10.0" />
</children>
</AnchorPane>
</content>
</TitledPane>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0" />
</items>
</SplitPane>
</children>
</AnchorPane>
The text in the first TextArea blurred. Why it happens and how to fix it?
The problem occurs when you are using this combination: TitledPane -> AnchorPane (It does not matter which elements are embedded into the AnchorPane). When you are using the AnchorPane Constraints tool, nested elements are getting artifacts of the values of the Width, Height, LayoutBounds, BoundsInLocal and BoundsInParent. These artifacts affect the blur.
No constrains:
There are constrains:
For solving the problem don’t use combination TitledPane-> AnchorPane or don’t use tool AnchorPane Constraints.
You have wrapped the TextArea in the SplitPane in another AnchorPane. If you delete that the blur is gone. I don't know why but I could get it to work with this code.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<TitledPane animated="false" prefWidth="300.0" text="test2" AnchorPane.bottomAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<TextArea prefHeight="200.0" prefWidth="200.0"/>
</TitledPane>
<SplitPane dividerPositions="0.5" orientation="VERTICAL" prefHeight="200.0" prefWidth="160.0"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="300.0"
AnchorPane.topAnchor="0.0">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
<TitledPane animated="false" text="test" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
//deleted AnchorPane here
<TextArea prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="-10.0"
AnchorPane.leftAnchor="-10.0" AnchorPane.rightAnchor="-10.0"
AnchorPane.topAnchor="-10.0"/>
</TitledPane>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0"/>
</SplitPane>
</AnchorPane>

How to make Labels and TextFields reposition based on size of window

I have a few textfields and Labels in my fxml file. All of them lie on an Anchor Pane. While the TableViews get repositioned correctly when I maximize the Pane, labels and Text Fields dont change position and hence all of them look out of sync. Any clues will be helpful.
Here is the code to simulate the problem. When you maximize the fxml the heading goes out of whack.
FXMLDocument.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="600.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="testbed.FXMLDocumentController">
<children>
<Label fx:id="label" layoutX="126" layoutY="120" minHeight="16" minWidth="69" />
<SplitPane dividerPositions="0.14715719063545152" layoutX="175.0" layoutY="74.0" orientation="VERTICAL" prefHeight="600.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
<children>
<Label layoutX="234.0" layoutY="32.0" text="MAIN HEADING ">
<font>
<Font size="18.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
<children>
<SplitPane dividerPositions="0.4949664429530201" layoutX="52.0" layoutY="140.0" prefHeight="507.0" prefWidth="598.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
</items>
</SplitPane>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>

Resources