【发布时间】:2020-01-08 19:45:23
【问题描述】:
我正在开发一个 JavaFX 应用程序,并且在制作我的应用程序的那种“仪表板”时遇到了以下问题。应用程序的结构如下:
这是主控制器的菜单或“仪表板”。我遇到的问题是能够将命令从“控制面板”发送到主视图。
appFrame 和 controlPanel 的 fx:id 是显示这些视图的位置。我怎样才能让这两个面板(每个都有自己的控制器)进行通信?
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.Cursor?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.effect.DropShadow?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane fx:id="parent" prefHeight="600" prefWidth="1024.0" styleClass="parent" stylesheets="@stylesheet.css" xmlns="http://javafx.com/javafx/" xmlns:fx="http://javafx.com/fxml/" fx:controller="main.DashboardController">
<VBox alignment="TOP_CENTER" prefHeight="600.0" prefWidth="300.0" styleClass="sidebar">
<Pane prefHeight="75.0" prefWidth="300.0" style="-fx-background-color: #AED6F1#AED6F1;">
<padding>
<Insets left="10.0" />
</padding>
<ImageView fitHeight="75.0" fitWidth="236.0" layoutX="24.0" layoutY="8.0" pickOnBounds="true" preserveRatio="true">
<Image url="main/logo.png" /></ImageView>
</Pane>
<HBox id="projects" alignment="CENTER_LEFT" layoutX="10.0" layoutY="132.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" onMouseClicked="#handleViewChanged" prefHeight="40.0" prefWidth="300.0" styleClass="btns">
<padding>
<Insets left="10.0" />
</padding>
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
<Label text="Projects" textFill="#7c8184">
<font>
<Font name="Calibri Light" size="15.0" />
</font>
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Label>
</HBox>
<HBox id="users" alignment="CENTER_LEFT" layoutX="10.0" layoutY="132.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" onMouseClicked="#handleViewChanged" prefHeight="40.0" prefWidth="300.0" styleClass="btns">
<padding>
<Insets left="10.0" />
</padding>
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
<Label text="Users" textFill="#7c8184">
<font>
<Font name="Calibri Light" size="15.0" />
</font>
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Label>
</HBox>
<HBox id="organizations" alignment="CENTER_LEFT" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" onMouseClicked="#handleViewChanged" prefHeight="40.0" prefWidth="300.0" styleClass="btns">
<padding>
<Insets left="10.0" />
</padding>
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
<Label text="Organizations" textFill="#7c8184">
<font>
<Font name="Calibri Light" size="15.0" />
</font>
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Label>
</HBox>
<HBox id="templates" alignment="CENTER_LEFT" layoutX="10.0" layoutY="252.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" onMouseClicked="#handleViewChanged" prefHeight="40.0" prefWidth="300.0" styleClass="btns">
<padding>
<Insets left="10.0" />
</padding>
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
<Label text="Templates" textFill="#7c8184">
<font>
<Font name="Calibri Light" size="15.0" />
</font>
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Label>
</HBox>
<VBox prefHeight="10" prefWidth="300.0" styleClass="box" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets />
</VBox.margin>
<padding>
<Insets left="10.0" top="10.0" />
</padding>
</VBox>
<BorderPane fx:id="controlPane" prefHeight="150.0" prefWidth="300.0" styleClass="box" />
</VBox>
<VBox layoutX="300.0" prefHeight="600.0" prefWidth="724.0">
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="75.0" prefWidth="724.0" style="-fx-background-color: #DCDCDC;">
<effect>
<DropShadow blurType="ONE_PASS_BOX" color="#e8e4e4" height="10.0" radius="4.5" width="10.0" />
</effect>
<Label fx:id="titleText" layoutX="14.0" layoutY="24.0" text="Welcome" textFill="#7c8184">
<font>
<Font size="18.0" />
</font>
</Label>
</Pane>
<HBox alignment="CENTER" />
<BorderPane fx:id="appFrame" prefHeight="536.0" prefWidth="724.0">
<center>
<fx:include source="welcome.fxml" />
</center>
</BorderPane>
</VBox>
</AnchorPane>
【问题讨论】: