我正在使用eclipse和javafx。我创建了一个项目,eclipse生成了Main.java和application.css(它是空的)。之后我使用场景bulider创建了一些.fxml文件。当我尝试运行应用程序时,它只是打开一个空框而不考虑我在场景构建器中创建的内容。
我做错了什么? 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>
答案 0 :(得分:1)
您需要加载FXML文件以填充应用程序的对象图
//BorderPane root = new BorderPane();
Parent root = FXMLLoader.load(getClass().getResource("/Testing.fxml"));