如何在JavaFX中将侦听器添加到手风琴

时间:2019-04-12 10:56:05

标签: java javafx listener

我正在尝试编写一个程序,您可以在其中浏览选项卡,然后在选项卡中具有多个TitledPane,其中具有一些功能。 对于其中一些,有一些字段要填写。我希望询问用户是否要在更改TitledPane或Tabs时保存在字段中写的内容。

这就是为什么我想在我创建的手风琴的方法“ getExpandedPane”上添加侦听器的原因。这样我就知道哪个TitledPane当前处于活动状态。

也许您知道该怎么做,或者是另一种解决方案...

预先感谢

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Accordion?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.TitledPane?>
<?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.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>

<BorderPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxclinic.MainViewController">
   <center>
      <TabPane fx:id="tabPaneFunctions" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="374.0" prefWidth="800.0" tabClosingPolicy="UNAVAILABLE" tabMaxHeight="150.0" tabMinHeight="10.0" tabMinWidth="150.0" BorderPane.alignment="CENTER">
         <tabs>
            <Tab fx:id="appointmen" text="Appointments">
               <content>
                  <Accordion fx:id="appointmentsAccordion" maxWidth="1.7976931348623157E308" minHeight="-Infinity" prefHeight="78.0" prefWidth="800.0">
                     <panes>
                        <TitledPane fx:id="addAppointment" animated="false" maxWidth="1.7976931348623157E308" text="Add an appointment">
                           <content>
                              <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
                           </content>
                        </TitledPane>
                        <TitledPane fx:id="deletePatient" animated="false" maxWidth="1.7976931348623157E308" text="Delete patient">
                           <content>
                              <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
                           </content>
                        </TitledPane>
                        <TitledPane fx:id="searchPatient" animated="false" maxWidth="1.7976931348623157E308" text="Search for patient informations">
                           <content>
                              <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
                           </content>
                        </TitledPane>
                     </panes>
                  </Accordion>
               </content>
               <graphic>
                  <ImageView fitHeight="50.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@../img/appointment.png" />
                     </image>
                  </ImageView>
               </graphic>
            </Tab>
            <Tab text="Doctors">
               <content>
                  <Accordion fx:id="doctorsAccordion" maxWidth="1.7976931348623157E308" prefHeight="78.0" prefWidth="800.0">
                     <panes>
                        <TitledPane fx:id="listDoctors" animated="false" text="Show the list of doctors">
                           <content>
                              <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
                           </content>
                        </TitledPane>
                        <TitledPane fx:id="addDoctor" animated="false" text="Add a doctor">
                           <content>
                              <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
                           </content>
                        </TitledPane>
                        <TitledPane fx:id="deleteDoctor" animated="false" text="Delete a doctor">
                           <content>
                              <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
                           </content>
                        </TitledPane>
                     </panes>
                  </Accordion>
               </content>
               <graphic>
                  <ImageView fitHeight="50.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@../img/doctor.png" />
                     </image>
                  </ImageView>
               </graphic>
            </Tab>
            <Tab text="Patients">
               <content>
                  <Accordion fx:id="patientsAccordion" maxWidth="1.7976931348623157E308" prefHeight="78.0" prefWidth="800.0">
                     <panes>
                        <TitledPane fx:id="addPatient" animated="false" text="Add a patient">
                           <content>
                              <GridPane>
                                <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 minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                                </rowConstraints>
                                 <children>
                                    <TextField GridPane.columnIndex="1" GridPane.rowIndex="1" />
                                    <Label text="Identification number" GridPane.rowIndex="1" />
                                    <Label text="First name" GridPane.rowIndex="2" />
                                    <Label text="Surname" GridPane.rowIndex="3" />
                                    <Label text="Phone Number" GridPane.rowIndex="4" />
                                    <TextField GridPane.columnIndex="1" GridPane.rowIndex="2" />
                                    <TextField GridPane.columnIndex="1" GridPane.rowIndex="3" />
                                    <TextField GridPane.columnIndex="1" GridPane.rowIndex="4" />
                                    <VBox prefHeight="200.0" prefWidth="100.0" GridPane.columnIndex="3" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.rowSpan="2" GridPane.valignment="CENTER">
                                       <children>
                                          <ImageView fitHeight="117.0" fitWidth="112.0" pickOnBounds="true" preserveRatio="true">
                                             <image>
                                                <Image url="@../img/addportrait_patient.png" />
                                             </image>
                                          </ImageView>
                                          <Label alignment="CENTER" contentDisplay="CENTER" prefHeight="18.0" prefWidth="113.0" text="Photo" textAlignment="CENTER" />
                                       </children>
                                    </VBox>
                                    <HBox prefHeight="100.0" prefWidth="200.0" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="6" GridPane.valignment="CENTER">
                                       <children>
                                          <Button alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="26.0" prefWidth="59.0" text="Clean">
                                             <HBox.margin>
                                                <Insets />
                                             </HBox.margin>
                                          </Button>
                                          <Button alignment="CENTER" contentDisplay="CENTER" defaultButton="true" mnemonicParsing="false" prefHeight="26.0" prefWidth="60.0" text="Save">
                                             <HBox.margin>
                                                <Insets left="20.0" />
                                             </HBox.margin>
                                          </Button>
                                       </children>
                                    </HBox>
                                 </children>
                                 <padding>
                                    <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
                                 </padding>
                              </GridPane>
                           </content>
                        </TitledPane>
                        <TitledPane fx:id="deletePatient" animated="false" text="Delete patient">
                           <content>
                              <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
                           </content>
                        </TitledPane>
                        <TitledPane fx:id="searchPatient" animated="false" text="Search for patient informations">
                           <content>
                              <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
                           </content>
                        </TitledPane>
                     </panes>
                  </Accordion>
               </content>
               <graphic>
                  <ImageView fitHeight="50.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@../img/patient.png" />
                     </image>
                  </ImageView>
               </graphic>
            </Tab>
         </tabs>
      </TabPane>
   </center>
   <top>
      <Text fx:id="clinicName" fill="#008dff" strokeType="OUTSIDE" strokeWidth="0.0" textAlignment="CENTER" BorderPane.alignment="CENTER">
         <font>
            <Font name="Arial" size="20.0" />
         </font>
      </Text>
   </top>
</BorderPane>

0 个答案:

没有答案