节点不可见(空白窗口)

时间:2020-05-21 12:46:21

标签: java javafx

我的代码:

主类:

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("sample.fxml"));
        Scene scene = new Scene(fxmlLoader.load());

        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Base.java

@DefaultProperty("children")
public class Base extends HBox {

    public final ObservableList<Node> children;
    public final VBox foundation;

    public Base() {
        foundation = new VBox();
        children = foundation.getChildren();
        super.getChildren().add(foundation);
    }

    public final ObservableList<Node> getChildren() {
        return children;
    }

}

sample.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import sample.Base?>
<?import javafx.scene.control.Button?>
<Base xmlns:fx="gui" fx:controller="sample.Controller">
    <children>
        <Button text="test"/>
    </children>
</Base>

Main类中的Scene对象不为null。 Controller.java为空。 为什么我的按钮没有显示?有什么想法吗?

顺便说一句。舞台(窗口)的大小就像有一些按钮一样,但它不可见(也许它在某个节点下?但是怎么来的?)

我正在使用OpenJDK和OpenJFX(14.0.1)

0 个答案:

没有答案
相关问题