JavaFX abstract controller inheritance didn't work - javafx

I have a big problem while coding my application.
Well, I try to extend my ReaderController class, which is abstract and it is set as controller in my fxml file.
There is my code:
public abstract class ReaderController extends AnchorPane{
#FXML
TextField id;
#FXML
TextField name;
#FXML
TextField surname;
#FXML
TextField PESEL;
#FXML
TextField dateOfBirth;
#FXML
TextField documentType;
#FXML
TextField documentNumber;
#FXML
TextField email;
#FXML
TextField phoneNumber;
#FXML
TextField street;
#FXML
TextField city;
#FXML
Button addReader;
Parent root;
public ReaderController()
{
}
And there is my subclass:
public class EditReaderController extends ReaderController{
public EditReaderController() throws IOException
{
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/AddUser.fxml"));
root= (Parent) loader.load();
loader.setController(this);
Stage stage = new Stage();
stage.setTitle("Edit User");
stage.setScene(new Scene(root));
stage.setResizable(false);
stage.show();
}
public void initialize(){
addReader.setText("Edit!");
id.setText(String.valueOf(SQLController.getInstance().getLastIndexOfReader()));
}
I have an error:
aused by: java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:927)
... 75 more
So how can I extend my abstract controller into my EditReaderController ?
UPD 1 my fxml file
<?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.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?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/9" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.library.controllers.ReaderController">
<children>
<HBox layoutX="151.0" layoutY="64.0" prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<VBox prefHeight="400.0" prefWidth="129.0">
<children>
<GridPane prefHeight="300.0" prefWidth="129.0">
<columnConstraints>
<ColumnConstraints halignment="CENTER" 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>
<Label text="Nr czytelnika" />
<Label text="ImiÄ™" GridPane.rowIndex="1" />
<Label text="Nazwisko" GridPane.rowIndex="2" />
<Label text="PESEL" GridPane.rowIndex="3" />
<Label text="Data urodzenia" GridPane.rowIndex="4" />
</children>
<VBox.margin>
<Insets top="15.0" />
</VBox.margin>
</GridPane>
</children>
</VBox>
<VBox prefHeight="400.0" prefWidth="178.0">
<children>
<GridPane prefHeight="300.0" prefWidth="178.0">
<columnConstraints>
<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>
<TextField fx:id="id" editable="false" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="26.0" prefWidth="34.0" />
<TextField fx:id="name" GridPane.rowIndex="1">
<GridPane.margin>
<Insets right="25.0" />
</GridPane.margin>
</TextField>
<TextField fx:id="surname" GridPane.rowIndex="2">
<GridPane.margin>
<Insets right="25.0" />
</GridPane.margin>
</TextField>
<TextField fx:id="PESEL" GridPane.rowIndex="3">
<GridPane.margin>
<Insets right="25.0" />
</GridPane.margin>
</TextField>
<TextField fx:id="dateOfBirth" editable="false" GridPane.rowIndex="4">
<GridPane.margin>
<Insets right="25.0" />
</GridPane.margin>
</TextField>
</children>
<VBox.margin>
<Insets top="15.0" />
</VBox.margin>
</GridPane>
</children>
</VBox>
<VBox prefHeight="200.0" prefWidth="100.0">
<children>
<GridPane prefHeight="300.0" prefWidth="99.0">
<columnConstraints>
<ColumnConstraints halignment="CENTER" 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 minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Typ dokumentu" />
<Label text="Nr dokumentu" GridPane.rowIndex="1" />
<Label text="E-mail" GridPane.rowIndex="2" />
<Label text="Nr telefonu" GridPane.rowIndex="3" />
<Label text="Ulica" GridPane.rowIndex="4" />
<Label text="Miasto" GridPane.rowIndex="5" />
</children>
<VBox.margin>
<Insets top="15.0" />
</VBox.margin>
</GridPane>
</children>
</VBox>
<VBox prefHeight="400.0" prefWidth="195.0">
<children>
<GridPane prefHeight="300.0" prefWidth="195.0">
<columnConstraints>
<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 minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<TextField fx:id="documentType">
<GridPane.margin>
<Insets right="25.0" />
</GridPane.margin>
</TextField>
<TextField fx:id="documentNumber" GridPane.rowIndex="1">
<GridPane.margin>
<Insets right="25.0" />
</GridPane.margin>
</TextField>
<TextField fx:id="email" GridPane.rowIndex="2">
<GridPane.margin>
<Insets right="25.0" />
</GridPane.margin>
</TextField>
<TextField fx:id="phoneNumber" GridPane.rowIndex="3">
<GridPane.margin>
<Insets right="25.0" />
</GridPane.margin>
</TextField>
<TextField fx:id="street" GridPane.rowIndex="4">
<GridPane.margin>
<Insets right="25.0" />
</GridPane.margin>
</TextField>
<TextField fx:id="city" GridPane.rowIndex="5">
<GridPane.margin>
<Insets right="25.0" />
</GridPane.margin>
</TextField>
</children>
<VBox.margin>
<Insets top="15.0" />
</VBox.margin>
</GridPane>
<Button fx:id="addReader" alignment="CENTER" mnemonicParsing="false" onAction="#onAddReaderAction" text="Dodaj" textAlignment="CENTER">
<VBox.margin>
<Insets left="100.0" top="25.0" />
</VBox.margin>
</Button>
</children>
</VBox>
</children>
</HBox>
</children>
</AnchorPane>

Why are you using an abstract class in your fxml?
Look at this line:
fx:controller="com.library.controllers.ReaderController"
You have a non-abstract subclass. Why not use it?
fx:controller="com.library.controllers.EditReaderController"
Or use your own non-abstract class.
I didn't see any abstract members in ReaderController.
Removing the abstract modifier may also solve this.
Also, it's really confusing that your controller class is extending AnchorPane..
Also, according to #sillyfly in the comments,
there really isn't much use calling setController after the call to FXMLLoader#load, as by this point the fields have been injected... I think it would even raise an exception about the controller already being set...
According to the comment,
I know it, but i didn't know, how to set a new Controller through action ( for example clicked Edit or Add button)
You should first read https://docs.oracle.com/javafx/2/ui_controls/button.htm to know how to run some code when a button is clicked, and run
loader.setController(your new controller);
when your button is clicked, and remove the fx:controller field, because you already set the controller in your logic code.

Related

I cant parse text from the JavaFX TextArea and TextField [duplicate]

This question already has answers here:
Canvas pane doesn't refreshing(JavaFX) [closed]
(1 answer)
Is #FXML needed for every declaration?
(3 answers)
Closed 7 days ago.
I am using the JavaFX as my GUI and JDBC as my API for database. The method saveCard() is supposed to parse text from the JavaFX TextArea and TextField which then saves the data through the database.insertQuestionAndAnswer() method. It is not and only returning an empty string.
Java code:
package workspace;
import java.io.IOException;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
public class CardMakerController {
#FXML
private CardDatabase database = new CardDatabase();
private TextField questionContainer = new TextField();
private TextArea answerContainer = new TextArea();
public void changeViewToDefaultScreen(ActionEvent e) throws IOException {
App.setRootForScene("welcomeScreen");
}
public void saveCard() {
String cardQuestion = questionContainer.getText();
String cardAnswer = answerContainer.getText();
System.out.println("cardQuestion" + cardAnswer);
database.insertQuestionAndAnswer(cardQuestion, cardAnswer);
}
}
FXML file:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.DialogPane?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<GridPane prefHeight="373.0" prefWidth="579.0" style="-fx-background-color: khaki; -fx-border-color: orange;" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="workspace.CardMakerController">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<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 minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="CREATE FLASH CARD" textAlignment="CENTER" wrapText="true" GridPane.columnIndex="2">
<font>
<Font name="Cascadia Code Regular" size="12.0" />
</font>
</Label>
<Label text="QUESTION:" GridPane.columnIndex="1" GridPane.rowIndex="1" GridPane.valignment="TOP">
<font>
<Font name="Cascadia Code Regular" size="12.0" />
</font>
</Label>
<Label text="ANSWER/S:" GridPane.columnIndex="1" GridPane.rowIndex="2" GridPane.valignment="BOTTOM">
<font>
<Font name="Cascadia Code Regular" size="12.0" />
</font>
<GridPane.margin>
<Insets bottom="12.0" />
</GridPane.margin>
</Label>
<TextField fx:id="questionContainer" prefHeight="25.0" prefWidth="125.0" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="1" GridPane.valignment="BOTTOM" />
<TextArea fx:id="answerContainer" prefHeight="70.0" prefWidth="348.0" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="3" GridPane.rowSpan="2" />
<DialogPane style="-fx-background-color: KHAKI;" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="5" />
<Button mnemonicParsing="false" onAction="#saveCard" style="-fx-background-color: orange;" text="Save Card" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="5" GridPane.valignment="CENTER">
<font>
<Font name="Cascadia Code Regular" size="12.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#changeViewToDefaultScreen" style="-fx-background-color: orange;" text="Change View" GridPane.columnIndex="3" GridPane.halignment="CENTER" GridPane.rowIndex="5" GridPane.valignment="CENTER">
<font>
<Font name="Cascadia Code Regular" size="12.0" />
</font>
</Button>
</children>
</GridPane>
I tried to check if the String parsed is null through an if loop to test it, but is not. When I check the database there is no word that is saved. It is empty pleas help

JavaFx: jfxTextField with icons

Hi I'm not able to add an icon to my jfxtextfield and found nothing about
could anyone help?
fxml:
<VBox fx:id="root" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="300.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<children>
<HBox fx:id="boxLogo" alignment="CENTER" prefHeight="100.0" prefWidth="300.0">
<children>
<FontAwesomeIconView glyphName="HOME" size="50">
<fill>
<LinearGradient endX="1.0" endY="1.0" startY="0.49047619047619045">
<stops>
<Stop color="#0d96ff" />
<Stop color="#010f1b" offset="1.0" />
</stops>
</LinearGradient>
</fill>
</FontAwesomeIconView>
</children>
</HBox>
<GridPane fx:id="boxField" alignment="CENTER" prefHeight="222.0" prefWidth="300.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="131.0" minHeight="10.0" prefHeight="108.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="142.0" minHeight="10.0" prefHeight="107.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="142.0" minHeight="10.0" prefHeight="107.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<JFXTextField fx:id="userTxt" alignment="CENTER" focusColor="#1cffb3" labelFloat="true" maxWidth="-Infinity" prefWidth="200.0" text="Digite o seu Login" unFocusColor="#00fffb" GridPane.halignment="CENTER" />
<JFXTextField alignment="CENTER" focusColor="#00ff77" maxWidth="-Infinity" prefWidth="200.0" text="Digite a sua senha" unFocusColor="#00fffb" GridPane.halignment="CENTER" GridPane.rowIndex="1" />
<JFXCheckBox text="Lembrar Usuario" GridPane.halignment="RIGHT" GridPane.rowIndex="2">
<GridPane.margin>
<Insets right="50.0" />
</GridPane.margin>
</JFXCheckBox>
</children>
</GridPane>
<HBox fx:id="boxButtons" alignment="TOP_CENTER" prefHeight="100.0" prefWidth="300.0" spacing="30.0">
<children>
<JFXButton buttonType="RAISED" prefHeight="25.0" prefWidth="86.0" ripplerFill="#09fff7" style="-fx-background-color: #0DA5E2;" text="Entrar" textFill="WHITE" textOverrun="CLIP">
<font>
<Font name="Arial" size="12.0" />
</font>
</JFXButton>
</children>
</HBox>
</children>
</VBox>
my controller:
public class MainController {
#FXML
private VBox root;
#FXML
private HBox boxLogo;
#FXML
private GridPane boxField;
#FXML
private HBox boxButtons;
#FXML
private JFXTextField userTxt;
public void initialize() {
FontAwesomeIconView icon = new FontAwesomeIconView(FontAwesomeIcon.USER);
}
}
I wanted to add the icon I created to my textfiedl userTxt
I don't know if this can be done by controller or just by css?
From what I found is through css, but I would need to add a folder with a photo to work I wanted to do that with an icon is possible?
I propose to add this in your controller :
myJFXTextField.setstyle("-fx-background
image:url('http://icons.iconarchive.com/icons/rockettheme/halloween/32/pumpkin-
icon.png');");
and this in your css
.text-field {
-fx-background-repeat: no-repeat;
-fx-background-position: right center;
-fx-font-size: 20;
}
You can use a path or URL

How to get same vertical size of TitledPanes in a Gridpane? (JavaFX, Scenebuilder)

i have a problem with the vertical size of the right TiteldPane (see picture below). Both TitledPanes are put in a GridPane. I want that the smaller one gets the same height like the left one. I tried to set the Vgrow to "always" of the right TitledPane, but nothing happened. Also i tried to do something with a Region without a success. Is this possible without giving them an absolut height?
Thanks for your help in advance.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<AnchorPane xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<children>
<ScrollPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<content>
<AnchorPane>
<children>
<GridPane hgap="20.0" vgap="20.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" />
<ColumnConstraints hgrow="SOMETIMES" />
</columnConstraints>
<rowConstraints>
<RowConstraints valignment="TOP" vgrow="ALWAYS" />
</rowConstraints>
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</padding>
<children>
<TitledPane animated="false" text="TitledPane">
<content>
<GridPane hgap="10.0" vgap="5.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints vgrow="SOMETIMES" />
<RowConstraints vgrow="SOMETIMES" />
<RowConstraints vgrow="SOMETIMES" />
<RowConstraints vgrow="SOMETIMES" />
<RowConstraints vgrow="SOMETIMES" />
<RowConstraints vgrow="SOMETIMES" />
<RowConstraints vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Label" GridPane.halignment="RIGHT" />
<Label GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text="Label" GridPane.halignment="RIGHT" GridPane.rowIndex="2" />
<Label GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label text="Label" GridPane.halignment="RIGHT" GridPane.rowIndex="4" />
<Label GridPane.columnIndex="1" GridPane.rowIndex="5" />
<TextField GridPane.columnIndex="1" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="2" />
<TextField fx:id="abgar10TF" GridPane.columnIndex="1" GridPane.rowIndex="4" />
</children>
</GridPane>
</content>
</TitledPane>
<TitledPane animated="false" text="TitledPane" GridPane.columnIndex="1" GridPane.valignment="TOP" GridPane.vgrow="ALWAYS">
<content>
<GridPane hgap="10.0" vgap="5.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints vgrow="SOMETIMES" />
<RowConstraints vgrow="SOMETIMES" />
<RowConstraints vgrow="SOMETIMES" />
<RowConstraints vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Label" GridPane.halignment="RIGHT" />
<Label GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text="Label" GridPane.halignment="RIGHT" GridPane.rowIndex="2" />
<Label GridPane.columnIndex="1" GridPane.rowIndex="3" />
<TextField GridPane.columnIndex="1" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="2" />
</children>
</GridPane>
</content>
</TitledPane>
</children>
</GridPane>
</children>
</AnchorPane>
</content>
</ScrollPane>
</children>
</AnchorPane>
You have to set max height for both TitlePanes to MAX_VALUE

How to add datepicker field like TextField, Label etc. in the .FXML file (JavaFX)

I am trying to add datepicker field in .fxml (JavaFX). But I don't what is correct way to do?
Please help me how to add datepicker field in .fxml file.
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.collections.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="705.9998779296875" prefWidth="499.9998779296875" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="processbuilder.controler.NewActivityController">
<children>
<GridPane prefHeight="615.9998779296875" prefWidth="499.9998779296875" AnchorPane.bottomAnchor="90.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label prefHeight="24.0" prefWidth="53.0" text="Name : " GridPane.columnIndex="0" GridPane.halignment="CENTER" GridPane.rowIndex="0" GridPane.valignment="CENTER" />
<Label text="Description :" translateY="30.0" GridPane.columnIndex="0" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="TOP" />
<TextField fx:id="name" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="0" />
<TextArea fx:id="desc" prefWidth="200.0" wrapText="true" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="177.0" minWidth="10.0" prefWidth="76.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="394.0" minWidth="10.0" prefWidth="394.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="194.0" minHeight="10.0" prefHeight="49.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="317.0" minHeight="10.0" prefHeight="265.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="194.0" minHeight="10.0" prefHeight="42.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="261.0" minHeight="10.0" prefHeight="261.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
<Button fx:id="create" mnemonicParsing="false" onAction="#handleCreateActivity" prefWidth="64.0" text="Create" AnchorPane.bottomAnchor="30.0" AnchorPane.leftAnchor="345.0" AnchorPane.rightAnchor="91.0" />
<Button fx:id="cancel" mnemonicParsing="false" onAction="#handleCancel" prefHeight="20.9998779296875" prefWidth="63.9998779296875" text="Cancel" AnchorPane.bottomAnchor="30.0" AnchorPane.leftAnchor="116.0" AnchorPane.rightAnchor="320.0" />
<Button fx:id="modify" layoutX="345.0" layoutY="655.0" mnemonicParsing="false" onAction="#handleModify" prefWidth="63.9998779296875" text="Modify" visible="false" />
</children>
</AnchorPane>
Just use a DatePicker tag to add a DatePicker in your fxml
A sample example where I have added a DatePicker to the provided FXML is:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.collections.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="705.9998779296875" prefWidth="499.9998779296875" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<GridPane prefHeight="615.9998779296875" prefWidth="499.9998779296875" AnchorPane.bottomAnchor="90.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label prefHeight="24.0" prefWidth="53.0" text="Name : " GridPane.columnIndex="0" GridPane.halignment="CENTER" GridPane.rowIndex="0" GridPane.valignment="CENTER" />
<Label text="Description :" translateY="30.0" GridPane.columnIndex="0" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="TOP" />
<TextField fx:id="name" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="0" />
<TextArea fx:id="desc" prefWidth="200.0" wrapText="true" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label prefHeight="24.0" prefWidth="87.0" text="DatePicker : " GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="CENTER" />
<DatePicker fx:id="datepicker" GridPane.columnIndex="1" GridPane.rowIndex="2" />
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="177.0" minWidth="10.0" prefWidth="76.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="394.0" minWidth="10.0" prefWidth="394.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="194.0" minHeight="10.0" prefHeight="49.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="317.0" minHeight="10.0" prefHeight="265.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="194.0" minHeight="10.0" prefHeight="42.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="261.0" minHeight="10.0" prefHeight="261.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
<Button fx:id="create" mnemonicParsing="false" onAction="#handleCreateActivity" prefWidth="64.0" text="Create" AnchorPane.bottomAnchor="30.0" AnchorPane.leftAnchor="345.0" AnchorPane.rightAnchor="91.0" />
<Button fx:id="cancel" mnemonicParsing="false" onAction="#handleCancel" prefHeight="20.9998779296875" prefWidth="63.9998779296875" text="Cancel" AnchorPane.bottomAnchor="30.0" AnchorPane.leftAnchor="116.0" AnchorPane.rightAnchor="320.0" />
<Button fx:id="modify" layoutX="345.0" layoutY="655.0" mnemonicParsing="false" onAction="#handleModify" prefWidth="63.9998779296875" text="Modify" visible="false" />
</children>
</AnchorPane>
<DatePicker xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" />
But if you work with FXML you should use the Scene Builder, which is a WYSIWYG editor.

resize stage components when resizing stage

The below screen shot is the default size of stage
when resized
how to resize the inner components when resizing the stage window accordingly?
<AnchorPane fx:id="mainpane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="809.0" prefWidth="860.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxhomeui_1.HomeUI_2Controller">
<children>
<VBox layoutX="695.0" layoutY="137.0" AnchorPane.bottomAnchor="341.0" AnchorPane.leftAnchor="695.0" AnchorPane.rightAnchor="-2.0" AnchorPane.topAnchor="137.0">
<children>
<SplitPane fx:id="sidebar" layoutX="695.0" layoutY="137.0" prefHeight="331.0" prefWidth="167.0" AnchorPane.bottomAnchor="341.0" AnchorPane.leftAnchor="695.0" AnchorPane.rightAnchor="-2.0" AnchorPane.topAnchor="137.0" />
</children>
</VBox>
<HBox layoutX="37.0" layoutY="163.0" AnchorPane.bottomAnchor="38.0" AnchorPane.leftAnchor="37.0" AnchorPane.rightAnchor="257.0" AnchorPane.topAnchor="163.0">
<children>
<ScrollPane fx:id="displayscroll" layoutX="37.0" layoutY="163.0" prefHeight="608.0" prefWidth="566.0" AnchorPane.bottomAnchor="29.0" AnchorPane.leftAnchor="37.0" AnchorPane.rightAnchor="197.0" AnchorPane.topAnchor="163.0">
<content>
<GridPane fx:id="gridpane" prefHeight="383.0" prefWidth="449.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<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>
</GridPane>
</content>
</ScrollPane>
</children>
</HBox>
<Pane layoutX="573.0" layoutY="46.0" AnchorPane.bottomAnchor="738.0" AnchorPane.leftAnchor="573.0" AnchorPane.rightAnchor="107.0" AnchorPane.topAnchor="46.0">
<children>
<ComboBox fx:id="categorycmb" prefHeight="25.0" prefWidth="180.0" />
</children>
</Pane>
<Pane layoutX="110.0" layoutY="108.0" AnchorPane.bottomAnchor="672.0" AnchorPane.leftAnchor="110.0" AnchorPane.rightAnchor="461.0" AnchorPane.topAnchor="108.0">
<children>
<ToggleButton fx:id="gamestbutton" layoutX="76.0" layoutY="4.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="71.0" stylesheets="#Togglebutton.css" text="Games" AnchorPane.topAnchor="112.0" />
<ToggleButton fx:id="songstbutton" layoutX="218.0" layoutY="4.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="71.0" stylesheets="#Togglebutton.css" text="Songs" AnchorPane.topAnchor="112.0" />
<ToggleButton fx:id="apptbutton" layoutX="5.0" layoutY="4.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="71.0" stylesheets="#Togglebutton.css" text="Apps" AnchorPane.topAnchor="112.0" />
<ToggleButton fx:id="moviestbutton" layoutX="147.0" layoutY="4.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="71.0" stylesheets="#Togglebutton.css" text="Movies" AnchorPane.topAnchor="112.0" />
</children>
</Pane>
<Pane layoutX="92.0" layoutY="44.0" AnchorPane.bottomAnchor="737.0" AnchorPane.leftAnchor="92.0" AnchorPane.rightAnchor="347.0" AnchorPane.topAnchor="44.0">
<children>
<TextField fx:id="searchtxt" prefHeight="28.0" prefWidth="421.0" promptText="Search" AnchorPane.bottomAnchor="737.0" AnchorPane.leftAnchor="92.0" AnchorPane.rightAnchor="347.0" AnchorPane.topAnchor="44.0" />
</children>
</Pane>
</children>
</AnchorPane>
FXML code (above) scrollpane and splitpane enclosed inside HBox and VBox respectively.
Also I want to keep space between images..

Resources