2017-06-20 4 views
0

Ich versuche, Auswahl Box zu füllen, aber etwas ging schief. hier ist mein CodeJavaFX8 FXML Controller initialisieren Methode nicht aufgerufen

Verwandte Teil Controller.java

public class BookingController implements Initializable { 

    @FXML 
    private ChoiceBox<String> orderType;  
    @Override 
    public void initialize(URL url, ResourceBundle rb) { 
     orderType=new ChoiceBox<>(); 
     orderType.getItems().add("LabShoot"); 
     orderType.getItems().add("SoftData"); 
     orderType.getItems().add("Booking"); 
    }  
} 

FXML.fxml

<?import javafx.scene.control.Button?> 
<?import javafx.scene.control.ChoiceBox?> 
<?import javafx.scene.control.DatePicker?> 
<?import javafx.scene.control.Label?> 
<?import javafx.scene.control.TextField?> 
<?import javafx.scene.layout.AnchorPane?> 
<?import javafx.scene.text.Font?> 

<AnchorPane id="AnchorPane" prefHeight="447.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Orders.BookingController"> 
    <children> 
     <ChoiceBox fx:id="orderType" layoutX="225.0" layoutY="59.0" onContextMenuRequested="#value_Changed" prefWidth="150.0" /> 
     <DatePicker layoutX="116.0" layoutY="118.0" prefHeight="25.0" prefWidth="173.0" /> 
     <ChoiceBox layoutX="387.0" layoutY="118.0" prefHeight="25.0" prefWidth="173.0" /> 
     <ChoiceBox layoutX="119.0" layoutY="188.0" prefHeight="25.0" prefWidth="173.0" /> 
     <ChoiceBox layoutX="387.0" layoutY="188.0" prefHeight="25.0" prefWidth="173.0" /> 
     <TextField layoutX="119.0" layoutY="257.0" prefHeight="25.0" prefWidth="173.0" /> 
     <TextField layoutX="388.0" layoutY="257.0" prefHeight="25.0" prefWidth="173.0" /> 
     <TextField layoutX="119.0" layoutY="325.0" prefHeight="25.0" prefWidth="173.0" /> 
     <Button layoutX="387.0" layoutY="325.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="173.0" text="Add" /> 
     <Label layoutX="30.0" layoutY="122.0" prefHeight="17.0" prefWidth="42.0" text="Date:" /> 
     <Label layoutX="214.0" layoutY="14.0" text="Customer Name" textFill="#2807ff"> 
     <font> 
      <Font size="24.0" /> 
     </font> 
     </Label> 
     <Label layoutX="336.0" layoutY="122.0" prefHeight="17.0" prefWidth="42.0" text="Time:" /> 
     <Label layoutX="22.0" layoutY="193.0" text="Booking Type:" /> 
     <Label layoutX="337.0" layoutY="192.0" text="Dealer:" /> 
     <Label layoutX="31.0" layoutY="329.0" prefHeight="17.0" prefWidth="42.0" text="Price:" /> 
     <Label layoutX="332.0" layoutY="261.0" text="Address:" /> 
     <Label layoutX="27.0" layoutY="261.0" text="Duration:" /> 
    </children> 
</AnchorPane> 

das Programm läuft korrekt, aber die Elemente i in Auswahlbox erscheint nicht setzen.

Antwort

0

Es ist wegen der

orderType=new ChoiceBox<>(); 

sollten Sie nie intialize Felder mit @FXML annoted. Wenn Sie das tun, werden Ihre Felder nicht mehr auf diejenigen verweisen, die vom FXML Loader geladen wurden (und die, die angezeigt werden).

+0

Ich habe es aber immer noch das gleiche Problem. Ich möchte eine Sache mehr löschen, ich setze 'System.out.println (" aufgerufen ");' in der Initialisierungsmethode, aber es wird auch nicht gedruckt. Das Hauptproblem besteht darin, dass die Initialisierungsmethode nicht aufgerufen wird. – Dosti

Verwandte Themen