Ich bin neu in Java Fx. Ich habe ein TabPanel mit 3 Tabs. Jede Registerkarte hat viele Steuerelemente (Text, Schaltflächen usw.), und ich möchte nur einen Controller für alle Tabs zuweisen. Der SceneBuilder lässt mich nur einen Controller für die gesamte Ansicht zuweisen, ich meine, nur das oberste Feld (der Stamm) hat die Option "Controller-Klasse", also Wie schreibt man den Code für alle Registerkarten einer Klasse?JavaFx TabPane: Want One Controller für 2 oder mehr Registerkarte
ich habe .fxml Datei als:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<Pane lns="http://javafx.com/javafx/8"xmlns:fx="http://javafx.com/fxml/1"
fx:controller="Application.LoginController">
<children>
<TabPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight=" -
Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0"
tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab text="Register">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0"
prefWidth="200.0">
<children>
<Label layoutX="27.0" layoutY="45.0" text="Name" />
<Label layoutX="27.0" layoutY="102.0" text="Password"
/>
<Label layoutX="27.0" layoutY="151.0" text="City" />
<Label layoutX="27.0" layoutY="204.0" text="Email" />
<Label layoutX="27.0" layoutY="246.0" text="Phone" />
<TextField fx:id="name"
layoutX="164.0"layoutY="41.0"/>
<TextField fx:id="passwd" layoutX="164.0"
layoutY="98.0" />
<TextField fx:id="city" layoutX="164.0"
layoutY="147.0" />
<TextField fx:id="email" layoutX="164.0"
layoutY="200.0" />
<TextField fx:id="phone" layoutX="164.0"
layoutY="242.0" />
<Button fx:id="register" layoutX="129.0"
layoutY="308.0" mnemonicParsing="false" text="Register" />
<Button fx:id="cancle" cancelButton="true"
layoutX="274.0" layoutY="308.0" mnemonicParsing="false" text="Cancle" />
</children>
</AnchorPane>
</content>
</Tab>
<Tab text="Login">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0"
prefWidth="200.0">
<children>
<Label layoutX="26.0" layoutY="57.0" text="User Name"
/>
<Label layoutX="26.0" layoutY="103.0" text="Password"
/>
<Button fx:id="myLogin" layoutX="145.0"
layoutY="186.0" mnemonicParsing="false" text="Login" />
<Button fx:id="cancle" cancelButton="true"
layoutX="274.0" layoutY="186.0" mnemonicParsing="false" text="Cancle" />
<TextField fx:id="uName" layoutX="145.0"
layoutY="53.0" prefHeight="25.0" prefWidth="205.0" />
<TextField fx:id="pwd" layoutX="148.0" layoutY="99.0"
prefHeight="25.0" prefWidth="200.0" />
</children>
</AnchorPane>
</content>
</Tab>
</tabs>
</TabPane>
</children>
</Pane>
Mögliches Duplikat von [So erstellen Sie mehrere javafx-Controller mit verschiedenen fxml-Dateien?] (Https://stackoverflow.com/questions/19342259/how-to-create-multiple-javafx-controllers-with-different-fxml -files) – Cris
aber ich möchte einen einzigen Controller für mehrere Registerkarte in einem einzigen fxml –
Ihr aktueller Controller kann alle Registerkarten damit umgehen. Es müssen keine verschiedenen Controller für verschiedene Registerkarten erstellt werden. – Sedrick