Reputation: 776
I am using eclipse with javafx. I created a project and eclipse generated Main.java and application.css (which is empty). Afterwards i created some .fxml files using the scene bulider. When i try to run the application however, it just opens an empty box without any regard to what I created in the scene builder.
What am I doing wrong? Main.java:
package application;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
BorderPane root = new BorderPane();
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
Testing.fxml:
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane prefHeight="437.0" prefWidth="524.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children><TabPane prefHeight="405.0" prefWidth="524.0" tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab text="Reservierung" />
<Tab text="Box" />
</tabs>
</TabPane>
<Button layoutX="139.1875" layoutY="39.0" mnemonicParsing="false" text="Search" AnchorPane.rightAnchor="175.8125" AnchorPane.topAnchor="70.0" />
<Label layoutX="111.0" layoutY="129.0" prefHeight="17.0" prefWidth="131.0" text="Ergebnisse Reservierung" AnchorPane.leftAnchor="11.0" AnchorPane.topAnchor="110.0" />
<TableView cacheShape="false" centerShape="false" layoutY="162.0" prefHeight="308.0" prefWidth="524.0" scaleShape="false">
<columns>
<TableColumn prefWidth="75.0" text="RNr" />
<TableColumn prefWidth="85.0" text="Box" />
<TableColumn prefWidth="97.0" text="Von" />
<TableColumn prefWidth="95.0" text="Bis" />
<TableColumn prefWidth="171.0" text="KundeNamen " />
</columns>
</TableView>
<Button defaultButton="true" layoutX="299.0" layoutY="200.0" mnemonicParsing="false" text="New" textOverrun="CLIP" AnchorPane.leftAnchor="100.0" AnchorPane.topAnchor="70.0" />
</children></AnchorPane>
Upvotes: 0
Views: 1932
Reputation: 159754
You need to load the FXML file to populate the object graph for the application
//BorderPane root = new BorderPane();
Parent root = FXMLLoader.load(getClass().getResource("/Testing.fxml"));
Upvotes: 1