I'm testing an application which can write texts to a TextArea as soon as I open a TitlePane. I coded my app so that when I click the title of titlepane2, some text should be written in the textArea2 and it's working fine.
But the problem is: how can some text be written when I click the finish button located in titlepane1?
As you can see, if the finish button clicked, titlepane2 is going to be expanded and some text should be written in textArea2.
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextArea;
import javafx.scene.control.TitledPane;
public class TitlePaneTestController implements Initializable {
#FXML private TitledPane titlePane1;
#FXML private TitledPane titlePane2;
#FXML private TextArea textArea1;
#FXML private TextArea textArea2;
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
#FXML
private void handleTitlePane1Clicked() {
textArea1.appendText("This is TitlePane 1");
}
#FXML
private void handleTitle1Finished() {
titlePane1.setExpanded(false);
titlePane2.setExpanded(true);
}
#FXML
private void handleTitlePane2Clicked() {
textArea2.appendText("This is TitlePane 2");
}
}
this is the FXML file
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="smallframework.TitlePaneTestController">
<children>
<Accordion layoutX="107.0" layoutY="101.0" prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<panes>
<TitledPane fx:id="titlePane1" animated="false" text="Step 1">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<VBox prefHeight="353.0" prefWidth="598.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<TextArea fx:id="textArea1" prefHeight="200.0" prefWidth="200.0" />
<Button mnemonicParsing="false" onAction="#handleTitle1Finished" text="Finish" />
</children>
</VBox>
</children>
</AnchorPane>
</content>
</TitledPane>
<TitledPane fx:id="titlePane2" animated="false" text="Step 2">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<VBox prefHeight="353.0" prefWidth="598.0">
<children>
<TextArea fx:id="textArea2" prefHeight="200.0" prefWidth="200.0" />
<Button mnemonicParsing="false" text="Finish" />
</children>
</VBox>
</children>
</AnchorPane>
</content>
</TitledPane>
</panes>
</Accordion>
</children>
</AnchorPane>
Register a listener with the expandedProperty of each titled pane:
#Override
public void initialize(URL url, ResourceBundle rb) {
titlePane1.expandedProperty().addListener((obs, wasExpanded, isNowExpanded) -> {
if (isNowExpanded) {
textArea1.appendText("Titled Pane 1 selected");
}
}
titlePane2.expandedProperty().addListener((obs, wasExpanded, isNowExpanded) -> {
if (isNowExpanded) {
textArea2.appendText("Titled Pane 2 selected");
}
}
}
Related
in Controller implement Initializable the initialize method I want get box LayoutBounds,but why layoutBounds all property is zero?
package com.erayt.studio.process.component.aggregate.controller;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.layout.VBox;
import java.net.URL;
import java.util.ResourceBundle;
public class TestController implements Initializable {
#FXML
private VBox box;
#Override
public void initialize(URL url, ResourceBundle resourceBundle) {
System.out.println(box.getLayoutBounds());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>
<VBox fx:id="box" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.erayt.studio.process.component.aggregate.controller.TestController">
<children>
<TabPane prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab text="Untitled Tab 1">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</Tab>
<Tab text="Untitled Tab 2">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</Tab>
</tabs>
</TabPane>
</children>
</VBox>
I'm Creating a loading screen for my application which has complex Neumorphism Design using InnerShadow, although CPU and RAM usage is less, the application causes lagging effect for animation like Circular Progress Indicator of Gluon charm-glisten.jar as well as PathTransition animation. In this loading screen you can see a red rectangle moving around the design and the progress indicator in blue color in the innermost layer
Java Code:
package application;
import java.net.URL;
import java.util.*;
import com.gluonhq.charm.glisten.control.ProgressIndicator;
import javafx.animation.*;
import javafx.animation.PathTransition.*;
import javafx.application.*;
import javafx.concurrent.*;
import javafx.event.*;
import javafx.fxml.*;
import javafx.stage.*;
import javafx.util.*;
import javafx.scene.*;
import javafx.scene.input.*;
import javafx.scene.layout.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
public class Main extends Application implements Initializable
{
private double xOffset = 0;
private double yOffset = 0;
#FXML
ProgressIndicator pg1;
static AnchorPane root;
private PathTransition pathTransitionCircle;
public void start(Stage primaryStage)
{
try
{
primaryStage.initStyle(StageStyle.TRANSPARENT);
root = FXMLLoader.load(getClass().getResource("Test1.fxml"));
Scene scene = new Scene(root,600,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
scene.setFill(javafx.scene.paint.Color.TRANSPARENT);
primaryStage.setScene(scene);
primaryStage.show();
root.setOnMousePressed(new EventHandler<MouseEvent>()
{
public void handle(MouseEvent e)
{
xOffset = e.getSceneX();
yOffset = e.getSceneY();
}
});
root.setOnMouseDragged(new EventHandler<MouseEvent>()
{
public void handle(MouseEvent e)
{
primaryStage.setX(e.getScreenX() - xOffset);
primaryStage.setY(e.getScreenY() - yOffset);
}
});
Rectangle rect2 = new Rectangle(0, 0, 20, 20);
rect2.setArcHeight(10);
rect2.setArcWidth(10);
rect2.setFill(Color.RED);
root.getChildren().add(rect2);
Path path2 = createEllipsePath(400, 200, 150, 150, 0);
path2.setLayoutX(57);
path2.setLayoutY(10);
root.getChildren().add(path2);
pathTransitionCircle = new PathTransition();
pathTransitionCircle.setDuration(Duration.seconds(6));
pathTransitionCircle.setPath(path2);
pathTransitionCircle.setNode(rect2);
pathTransitionCircle.setOrientation(OrientationType.ORTHOGONAL_TO_TANGENT);
pathTransitionCircle.setCycleCount(PathTransition.INDEFINITE);
pathTransitionCircle.setInterpolator(Interpolator.LINEAR);
pathTransitionCircle.setAutoReverse(false);
pathTransitionCircle.play();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
launch(args);
}
#Override
public void initialize(URL arg0, ResourceBundle arg1)
{
Task<Void> task = new Task<Void>()
{
protected Void call() throws Exception
{
for (int i = 0; i <= 100; i++)
{
updateProgress(i, 100);
Thread.sleep(40);
}
//Platform.runLater(() -> primaryStage.close());
return null;
}
};
pg1.progressProperty().unbind();
pg1.progressProperty().bind(task.progressProperty());
Thread th = new Thread(task);
th.setDaemon(true);
th.start();
task.setOnSucceeded(new EventHandler<WorkerStateEvent>()
{
public void handle(WorkerStateEvent arg0)
{
try
{
/*primaryStage.close();
primaryStage = null;
System.gc();
FXML_Loader f1 = new FXML_Loader();
f1.intermediate();*/
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
}
private Path createEllipsePath(double centerX, double centerY, double radiusX, double radiusY, double rotate)
{
ArcTo arcTo = new ArcTo();
arcTo.setX(centerX - radiusX + 1); // to simulate a full 360 degree celcius circle.
arcTo.setY(centerY - radiusY);
arcTo.setSweepFlag(false);
arcTo.setLargeArcFlag(true);
arcTo.setRadiusX(radiusX);
arcTo.setRadiusY(radiusY);
arcTo.setXAxisRotation(rotate);
Path path = new Path();
path.getElements().addAll(
new MoveTo(centerX - radiusX, centerY - radiusY),
arcTo,
new ClosePath()); // close 1 px gap.
path.setStroke(Color.BLUE);
path.getStrokeDashArray().setAll(5d, 5d);
return path;
}
}
FXML Code:
<?xml version="1.0" encoding="UTF-8"?>
<?import com.gluonhq.charm.glisten.control.ProgressIndicator?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.effect.InnerShadow?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: transparent;" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Main">
<children>
<VBox alignment="CENTER" layoutX="163.5" layoutY="63.5" prefHeight="290.0" prefWidth="290.0" style="-fx-background-color: #3D4956; -fx-background-radius: 150;">
<effect>
<InnerShadow color="#00000070" offsetX="-4.0" offsetY="-4.0">
<input>
<InnerShadow color="#a7a7a7bf" offsetX="4.0" offsetY="4.0" />
</input>
</InnerShadow>
</effect>
<children>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: #3D4956; -fx-background-radius: 150;" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</VBox.margin>
<effect>
<InnerShadow color="#0000008c" offsetX="4.0" offsetY="4.0">
<input>
<InnerShadow color="#a6a6a65c" offsetX="-4.0" offsetY="-4.0" />
</input>
</InnerShadow>
</effect>
<children>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: #3D4956; -fx-background-radius: 150;" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</VBox.margin>
<effect>
<InnerShadow color="#0000008c" offsetX="-4.0" offsetY="-4.0">
<input>
<InnerShadow color="#a6a6a65c" offsetX="4.0" offsetY="4.0" />
</input>
</InnerShadow>
</effect>
<children>
<VBox prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: #3D4956; -fx-background-radius: 150;" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</VBox.margin>
<effect>
<InnerShadow color="#0000008c" offsetX="4.0" offsetY="4.0">
<input>
<InnerShadow color="#a6a6a65c" />
</input>
</InnerShadow>
</effect>
<children>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: #3D4956; -fx-background-radius: 150;" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</VBox.margin>
<effect>
<InnerShadow color="#0000008c" offsetX="-4.0" offsetY="-4.0">
<input>
<InnerShadow color="#a6a6a65c" offsetX="4.0" offsetY="4.0" />
</input>
</InnerShadow>
</effect>
<children>
<AnchorPane prefHeight="58.0" prefWidth="141.0" style="-fx-background-color: #3D4956; -fx-background-radius: 150;" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</VBox.margin>
<effect>
<InnerShadow color="#0000008c" offsetX="4.0" offsetY="4.0">
<input>
<InnerShadow color="#a6a6a65c" offsetX="-4.0" offsetY="-4.0" />
</input>
</InnerShadow>
</effect>
<children>
<ImageView fitHeight="42.0" fitWidth="50.0" layoutX="49.0" layoutY="40.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#logo/database1.png" />
</image>
</ImageView>
<Label layoutX="57.0" layoutY="81.0" prefHeight="19.0" prefWidth="34.0" text="SQL" textFill="YELLOW">
<font>
<Font name="System Bold Italic" size="14.0" />
</font>
</Label>
<Label layoutX="38.0" layoutY="97.0" prefHeight="20.0" prefWidth="73.0" text="Developer" textFill="YELLOW">
<font>
<Font name="System Bold Italic" size="14.0" />
</font>
</Label>
<ProgressIndicator fx:id="pg1" layoutX="8.0" layoutY="7.0" prefHeight="108.0" prefWidth="122.0" progress="1.0" radius="60.0" />
</children>
</AnchorPane>
</children>
</VBox>
</children>
</VBox>
</children>
</VBox>
</children>
</VBox>
</children>
</VBox>
</children>
</AnchorPane>
Loading Screen Design
I have created a Layout with FXML which consists of a BorderPane with a sideMenu and an innerBorderPane for other stuff...
But since I'm barely starting with FXML in JavaFX I just need to know how to do the next thing...
Custom.fxml (This is the main FXML layout)
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<VBox fx:controller="Transcoro.Controllers.TabManager" alignment="TOP_CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="442.0" prefWidth="338.0" spacing="5.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<HBox prefHeight="59.0" prefWidth="124.0">
<children>
<VBox prefHeight="59.0" prefWidth="90.0" style="-fx-background-color: blue;" />
<VBox alignment="CENTER_LEFT" prefHeight="59.0" prefWidth="165.0">
<children>
<Label text="Bienvenido, Rodolfo">
<font>
<Font name="System Bold" size="15.0" />
</font>
</Label>
<Label text="Administrador" />
</children>
<opaqueInsets>
<Insets />
</opaqueInsets>
<HBox.margin>
<Insets />
</HBox.margin>
<padding>
<Insets left="10.0" />
</padding>
</VBox>
</children>
<VBox.margin>
<Insets bottom="15.0" />
</VBox.margin>
</HBox>
<Button alignment="CENTER" contentDisplay="CENTER" maxWidth="1.7976931348623157E308" mnemonicParsing="false" nodeOrientation="LEFT_TO_RIGHT" text="Unidades" textAlignment="CENTER" textFill="#2491ff" />
<Button alignment="CENTER" contentDisplay="CENTER" maxWidth="1.7976931348623157E308" mnemonicParsing="false" nodeOrientation="LEFT_TO_RIGHT" text="Empleados" textAlignment="CENTER" textFill="#2491ff" />
<Button alignment="CENTER" contentDisplay="CENTER" maxWidth="1.7976931348623157E308" mnemonicParsing="false" nodeOrientation="LEFT_TO_RIGHT" text="Clientes" textAlignment="CENTER" textFill="#2491ff" />
<Button alignment="CENTER" contentDisplay="CENTER" maxWidth="1.7976931348623157E308" mnemonicParsing="false" nodeOrientation="LEFT_TO_RIGHT" text="Viajes" textAlignment="CENTER" textFill="#2491ff" />
</children>
<padding>
<Insets top="20.0" />
</padding>
</VBox>
sideMenu.fxml (This is the sideMenu FXML layout)
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<fx:root type="javafx.scene.layout.VBox" alignment="TOP_CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="442.0" prefWidth="338.0" spacing="5.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<HBox prefHeight="59.0" prefWidth="124.0">
<children>
<VBox prefHeight="59.0" prefWidth="90.0" style="-fx-background-color: blue;" />
<VBox alignment="CENTER_LEFT" prefHeight="59.0" prefWidth="165.0">
<children>
<Label text="Bienvenido, Rodolfo">
<font>
<Font name="System Bold" size="15.0" />
</font>
</Label>
<Label text="Administrador" />
</children>
<opaqueInsets>
<Insets />
</opaqueInsets>
<HBox.margin>
<Insets />
</HBox.margin>
<padding>
<Insets left="10.0" />
</padding>
</VBox>
</children>
<VBox.margin>
<Insets bottom="15.0" />
</VBox.margin>
</HBox>
<Button alignment="CENTER" contentDisplay="CENTER" maxWidth="1.7976931348623157E308" mnemonicParsing="false" nodeOrientation="LEFT_TO_RIGHT" text="Unidades" textAlignment="CENTER" textFill="#2491ff" />
<Button alignment="CENTER" contentDisplay="CENTER" maxWidth="1.7976931348623157E308" mnemonicParsing="false" nodeOrientation="LEFT_TO_RIGHT" text="Empleados" textAlignment="CENTER" textFill="#2491ff" />
<Button alignment="CENTER" contentDisplay="CENTER" maxWidth="1.7976931348623157E308" mnemonicParsing="false" nodeOrientation="LEFT_TO_RIGHT" text="Clientes" textAlignment="CENTER" textFill="#2491ff" />
<Button alignment="CENTER" contentDisplay="CENTER" maxWidth="1.7976931348623157E308" mnemonicParsing="false" nodeOrientation="LEFT_TO_RIGHT" text="Viajes" textAlignment="CENTER" textFill="#2491ff" />
</children>
<padding>
<Insets top="20.0" />
</padding>
</fx:root>
TabManager.java (This is the sideMenu JavaFX controller)
package Transcoro.Controllers;
import javafx.fxml.FXMLLoader;
import javafx.scene.layout.VBox;
import java.io.IOException;
public class TabManager extends VBox {
public TabManager(){
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/resources/view/sideMenu.fxml"));
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
try {
fxmlLoader.load();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}
}
MainLayout.java (This is the mainLayout JavaFX Controller)
package Transcoro.Core;
import Transcoro.Controllers.TabManager;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.*;
import java.io.IOException;
public class MainLayout extends BorderPane {
#FXML
private VBox sideMenu;
#FXML
private BorderPane innerContent;
#FXML
private HBox upperMenu;
#FXML
private ScrollPane contentScroll;
#FXML
private VBox otherPane;
public MainLayout(){
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/resources/view/Custom.fxml"));
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
try {
fxmlLoader.load();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
TabManager _tabs = new TabManager();
this.setSideMenu(_tabs);
}
What I want to do is the following:
I have two layouts, the base which is the main Layout and sideMenu layout in another FXML
When I instantiate the mainLayout in my root that works fine, then when I want to insert the TabManager (VBox) into sideMenu (VBox from FXML) it doesn't work... I'm doing this:
TabManager _tabs = new TabManager();
this.setSideMenu(_tabs);
The only way I have made it work is by adding:
this.setLeft(this.sideMenu);
OR
this.setLeft(_tabs);
Which I think it shouldn't work that why, because I'm already stating that sideMenu goes on the Left BorderPane side, any idea on how should I approach this?
Firstly, remove fx:controller="Transcoro.Controllers.TabManager" from Custom.fxml. The controller is MainLayout, which you will set via FXMLLoader.
Secondly, don't call fxmlLoader.setRoot(this); in MainLayout. You should instead retrieve the root node out from Custom.fxml, then add it to MainLayout, which itself is a BorderPane.
Parent root = fxmlLoader.getRoot();
this.setCenter(root);
This will put everything from Custom.fxml as the center child of MainLayout.
Thirdly, setLeft() is working because you are setting the TabManager instance (which is a VBox) as the left child of MainLayout. setSideMenu() (which is assumed as the setter of #FXML private VBox sideMenu does not work because sideMenu is just a reference injected into the controller. When you change this reference, it does not change the original layout.
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>
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();
}