Как добавить слушателя к аккордеону в JavaFX - PullRequest
0 голосов
/ 12 апреля 2019

Я пытаюсь закодировать программу, в которой вы можете перемещаться по вкладке, а затем во вкладке у вас есть несколько 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>
...