Я очень новичок в JavaFX.Я пытаюсь спроектировать некоторые пользовательские интерфейсы, используя конструктор сцен.Я хочу изменить сцену на пользовательский интерфейс, когда пользователь нажимает на кнопку клиентов на домашнем интерфейсе.Наконец-то мне удалось заставить его появиться.Но теперь это происходит так: (
Как я хочу, чтобы это появилось.
Как это выглядит сейчас.
Home.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<BorderPane fx:id="rootPane" prefHeight="570.0" prefWidth="817.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="home.HomeController">
<top>
<Pane prefHeight="167.0" prefWidth="817.0" style="-fx-background-color: #2e0050;" BorderPane.alignment="CENTER">
<children>
<Label layoutX="55.0" layoutY="32.0" text="Techster" textFill="WHITE">
<font>
<Font size="50.0" />
</font>
<padding>
<Insets left="10.0" />
</padding>
</Label>
<Label layoutX="54.0" layoutY="105.0" text="Management System" textFill="WHITE">
<font>
<Font size="20.0" />
</font>
<padding>
<Insets left="10.0" />
</padding>
</Label>
</children>
</Pane>
</top>
<center>
<AnchorPane prefHeight="390.0" prefWidth="743.0" style="-fx-background-color: #fff;" BorderPane.alignment="CENTER">
<children>
<GridPane hgap="10.0" layoutX="126.0" layoutY="92.0" prefHeight="149.0" prefWidth="491.0" vgap="10.0" AnchorPane.bottomAnchor="120.0" AnchorPane.leftAnchor="126.0" AnchorPane.rightAnchor="126.0" AnchorPane.topAnchor="120.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 maxHeight="194.0" minHeight="10.0" prefHeight="194.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button fx:id="btnCustomers" contentDisplay="TOP" mnemonicParsing="false" onAction="#handleButtonClicks" prefHeight="194.0" prefWidth="300.0" stylesheets="@style.css" text="CUSTOMERS">
<graphic>
<ImageView fitHeight="70.0" fitWidth="63.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../images/customers.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="btnContracts" contentDisplay="TOP" mnemonicParsing="false" onAction="#handleButtonClicks" prefHeight="202.0" prefWidth="309.0" stylesheets="@style.css" text="CONTRACTS" GridPane.columnIndex="1">
<graphic>
<ImageView fitHeight="70.0" fitWidth="63.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../images/contracts.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="btnEmployees" contentDisplay="TOP" maxHeight="300.0" maxWidth="300.0" mnemonicParsing="false" onAction="#handleButtonClicks" prefHeight="300.0" prefWidth="300.0" stylesheets="@style.css" text="EMPLOYEES" GridPane.columnIndex="2">
<graphic>
<ImageView fitHeight="70.0" fitWidth="63.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../images/employee.png" />
</image>
</ImageView>
</graphic>
</Button>
</children>
</GridPane>
</children>
</AnchorPane>
</center>
</BorderPane>
HomeController.java
package home;
import javafx.fxml.FXMLLoader;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
public class HomeController implements Initializable {
@FXML
private Button btnCustomers;
// @FXML
// private Button btnContracts;
//
// @FXML
// private Button btnEmployees;
@FXML
private BorderPane rootPane;
@FXML
private void handleButtonClicks(javafx.event.ActionEvent actionEvent) throws IOException {
if (actionEvent.getSource()==btnCustomers){
BorderPane pane = FXMLLoader.load(getClass().getResource("Customers.fxml"));
rootPane.getChildren().setAll(pane);
}
//
}
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
}
}
Customers.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>
<BorderPane prefHeight="570.0" prefWidth="817.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<top>
<Pane prefHeight="167.0" prefWidth="817.0" style="-fx-background-color: #2e0050;" BorderPane.alignment="CENTER">
<children>
<Label layoutX="100.0" layoutY="56.0" text="Customers" textFill="WHITE">
<font>
<Font size="60.0" />
</font>
</Label>
</children>
</Pane>
</top>
<center>
<SplitPane dividerPositions="0.5" orientation="VERTICAL" prefHeight="405.0" prefWidth="817.0" BorderPane.alignment="CENTER">
<items>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="198.0" prefWidth="817.0">
<children>
<Button layoutX="683.0" layoutY="21.0" mnemonicParsing="false" text="New Customer" AnchorPane.rightAnchor="30.0" AnchorPane.topAnchor="25.0" />
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="817.0">
<children>
<TableView layoutX="6.0" layoutY="28.0" prefHeight="169.0" prefWidth="807.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="28.0">
<columns>
<TableColumn maxWidth="1.7976931348623157E308" minWidth="130.0" prefWidth="130.0" text="ID" />
<TableColumn maxWidth="1.7976931348623157E308" minWidth="324.0" prefWidth="324.0" text="Name" />
<TableColumn maxWidth="1.7976931348623157E308" minWidth="200.0" prefWidth="200.0" text="Contact" />
<TableColumn maxWidth="1.7976931348623157E308" minWidth="154.0" prefWidth="154.0" text="Date Added" />
</columns>
</TableView>
<TextField layoutX="5.0" layoutY="2.0" prefHeight="25.0" prefWidth="722.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="90.0" AnchorPane.topAnchor="1.0" />
<Button layoutX="727.0" layoutY="2.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="83.0" text="Button" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="1.0" />
</children>
</AnchorPane>
</items>
</SplitPane>
</center>
</BorderPane>