我正在创建Javafx桌面应用程序。我遇到的问题是,如果我将控制器添加到fxml文件中,则控件会以某种方式消失。该程序使用淡入淡出过渡在fxml文件之间切换
AnchorPane reorderLevels,purchaseorder,onlineSales,generalLedger
,cashBook,payments,departmentalTransfers
,purchaseInvoice
,productMantainance,
branchTransfers,stockMovement,invoiceRegistration,stockTake;
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@Override
public void initialize(URL url, ResourceBundle rb) {
//load all the fxml screens when the buttons are clicked
try {
//screens for the application
reorderLevels = FXMLLoader.load(getClass().getResource("ReorderLevels.fxml"));
purchaseorder = FXMLLoader.load(getClass().getResource("PurchaseOrder.fxml"));
onlineSales = FXMLLoader.load(getClass().getResource("OnlineSales.fxml"));
generalLedger = FXMLLoader.load(getClass().getResource("GeneralLedger.fxml"));
cashBook = FXMLLoader.load(getClass().getResource("CashBook.fxml"));
departmentalTransfers = FXMLLoader.load(getClass().getResource("DepartmentalTransfers.fxml"));
purchaseInvoice = FXMLLoader.load(getClass().getResource("PurchaseInvoice.fxml"));
productMantainance = FXMLLoader.load(getClass().getResource("ProductMantainance.fxml"));
branchTransfers = FXMLLoader.load(getClass().getResource("BranchTransfers.fxml"));
stockMovement = FXMLLoader.load(getClass().getResource("StockMovement.fxml"));
payments = FXMLLoader.load(getClass().getResource("Payments.fxml"));
invoiceRegistration = FXMLLoader.load(getClass().getResource("InvoiceRegistration.fxml"));
stockTake = FXMLLoader.load(getClass().getResource("StockTake.fxml"));
//set each and every individual node when the buttons are clicked
setNode(reorderLevels);
} catch (IOException ex) {
Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void setNode(Node node) {
holderPane.getChildren().clear();
holderPane.getChildren().add((Node) node);
//the transition between the screens
FadeTransition ft = new FadeTransition(Duration.millis(1));
ft.setNode(node);
ft.setFromValue(0.1);
ft.setToValue(1);
ft.setCycleCount(1);
ft.setAutoReverse(false);
ft.play();
}
/* screens */
@FXML
private void switchReorderLevels(ActionEvent event) {
setNode(reorderLevels);
}
@FXML
private void switchOnlineSales(ActionEvent event) {
setNode(onlineSales);
}
@FXML
private void switchGeneralLedger(ActionEvent event) {
setNode(generalLedger);
}
@FXML
private void switchPurchaseOrder(ActionEvent event) {
setNode(purchaseorder);
}
@FXML
private void switchCashBook(ActionEvent event) {
setNode(cashBook);
}
@FXML
private void switchAlert(ActionEvent event) {
setNode(purchaseorder);
}
@FXML
private void switchPayments(ActionEvent event) {
setNode(payments);
}
@FXML
private void switchDepartmentalTransfers(ActionEvent event) {
setNode(departmentalTransfers);
}
@FXML
private void switchPurchaseInvoice(ActionEvent event) {
setNode(purchaseInvoice);
}
@FXML
private void switchProductMantainance(ActionEvent event) {
setNode(productMantainance);
}
@FXML
private void switchBranchTransfers(ActionEvent event) {
setNode(branchTransfers);
}
//this is a screen that will displayone of the layouts that will show re order levels
<AnchorPane id="AnchorPane" prefHeight="713.0" prefWidth="1219.0" style="-fx-background-color: white;" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label layoutX="24.0" layoutY="17.0" prefHeight="30.0" prefWidth="285.0" style="-fx-font-size: 20; -fx-font-weight: bold; -fx-text-fill: #7387A8;" text="ReOrder Levels" />
<Separator layoutX="25.0" layoutY="54.0" prefHeight="5.0" prefWidth="1191.0" />
<Pane fx:id="tbl_reorderLevels" layoutX="25.0" layoutY="108.0" prefHeight="413.0" prefWidth="1174.0" style="-fx-background-color: #EFEFEF;">
<children>
<JFXComboBox fx:id="cmd_reOrder_productCode" layoutX="48.0" layoutY="33.0" prefHeight="25.0" prefWidth="267.0" promptText="Product Code" />
<JFXTextField fx:id="txt_reOrder_reorderLevel" labelFloat="true" layoutX="48.0" layoutY="91.0" prefHeight="25.0" prefWidth="267.0" promptText="Reorder Level" />
///这是具有按钮的根布局,该按钮将使用淡入淡出过渡在屏幕之间导航
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?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.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<!-- root layout -->
<AnchorPane id="AnchorPane" nodeOrientation="LEFT_TO_RIGHT" prefHeight="623.0" prefWidth="1271.0" style="-fx-background-color: #fff;" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller = "dashboard.FXMLDocumentController">
<children>
<Pane layoutX="-2.0" prefHeight="81.0" prefWidth="1272.0" style="-fx-background-color: #0b8dee;" styleClass="head-background" stylesheets="@style.css" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label fx:id="labelEstock" layoutX="204.0" layoutY="-3.0" prefHeight="88.0" prefWidth="536.0" style="-fx-shape: round;" stylesheets="@custom.css" text="Oasys Estock" textFill="WHITE">
<font>
<Font name="Brush Script MT Italic" size="36.0" />
</font>
</Label>
<!-- <ImageView fx:id="imageEstock" fitHeight="110.0" fitWidth="92.0" layoutX="102.0" layoutY="8.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image
url="@../../../../AndroidStudioProjects/OasysEstock/app/src/main/res/drawable/fortified_icon.png" />
</image>
</ImageView> -->
</children>
</Pane>
<VBox layoutY="85.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="518.0" prefWidth="122.0" style="-fx-background-color: #0b8dee; -fx-background-radius: 15;">
<children>
<JFXButton id="btnReorderLevels" fx:id="btnReorderLevels" buttonType="RAISED" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" onAction="#switchReorderLevels" prefHeight="47.0" prefWidth="107.0" style="-fx-background-radius: 100;" text="ReOrder Levels" textFill="#f5f0f0">
<VBox.margin>
<Insets />
</VBox.margin>
<font>
<Font name="Calibri" size="12.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnInvoiceRegistration" onAction="#switchInvoiceRegistration" prefHeight="25.0" prefWidth="121.0" text="Invoice Registration" textFill="#f8f4f4" />
<JFXButton fx:id="btnPurchaseOrder" buttonType="RAISED" onAction="#switchPurchaseOrder" prefHeight="34.0" prefWidth="107.0" text="Purchase Order" textFill="#f5f0f0">
<font>
<Font name="Cambria" size="12.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnOnlineSales" onAction="#switchOnlineSales" prefHeight="39.0" prefWidth="107.0" text="Online Sales" textFill="#fff9f9">
<font>
<Font name="Calibri" size="12.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnGeneralLedger" onAction="#switchGeneralLedger" prefHeight="40.0" prefWidth="108.0" text="General Ledger" textFill="#f2eeee" />
<JFXButton fx:id="btnCashBook" onAction="#switchCashBook" prefHeight="35.0" prefWidth="104.0" text="Cash Book" textFill="#fffefe" />
<JFXButton fx:id="btnPayments" buttonType="RAISED" onAction="#switchPayments" prefHeight="25.0" prefWidth="114.0" text="Payments" textFill="#fcf6f6" />
<JFXButton fx:id="btnDepartmentalTransfers" buttonType="RAISED" layoutX="10.0" layoutY="205.0" onAction="#switchDepartmentalTransfers" prefHeight="25.0" prefWidth="114.0" text="Dept Transfers" textFill="#fcf6f6" />
<JFXButton fx:id="btnProductMantainance" buttonType="RAISED" layoutX="10.0" layoutY="230.0" onAction="#switchProductMantainance" prefHeight="56.0" prefWidth="121.0" text="Product Mantainance" textFill="#fcf6f6">
<font>
<Font size="11.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnPurchaseInvoice" buttonType="RAISED" layoutX="10.0" layoutY="255.0" onAction="#switchPurchaseInvoice" prefHeight="56.0" prefWidth="121.0" text="Purchase Invoice" textFill="#fcf6f6">
<font>
<Font size="11.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnBranchTransfers" buttonType="RAISED" layoutX="10.0" layoutY="311.0" onAction="#switchBranchTransfers" prefHeight="56.0" prefWidth="121.0" text="Branch Transfers" textFill="#fcf6f6">
<font>
<Font size="11.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnStockMovement" buttonType="RAISED" layoutX="10.0" layoutY="367.0" onAction="#switchStockMovement" prefHeight="56.0" prefWidth="121.0" text="Stock Movement" textFill="#fcf6f6">
<font>
<Font size="11.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnStockTake" buttonType="RAISED" layoutX="10.0" layoutY="448.0" onAction="#switchStockTake" prefHeight="56.0" prefWidth="121.0" text="Stock Take" textFill="#fcf6f6">
<font>
<Font size="11.0" />
</font>
</JFXButton>
</children>
<effect>
<InnerShadow blurType="TWO_PASS_BOX" choke="0.58" color="#212122" height="26.69" radius="10.620000000000001" width="17.79" />
</effect>
</VBox>
<AnchorPane fx:id="holderPane" layoutX="125.0" layoutY="96.0" prefHeight="507.0" prefWidth="1134.0"/>
</children>
</AnchorPane>