java - 我可以使用 springboot-javafx-support 从初级阶段获取根 Pane 吗?

标签 java spring-boot javafx-8

我有一个名为player.fxml的主页,它是一个BorderPane。类似这样的

<BorderPane xmlns="http://javafx.com/javafx"
            xmlns:fx="http://javafx.com/fxml"
            fx:controller="cn.will.controller.PlayerController"
            fx:id="root"
            prefHeight="670.0" prefWidth="1020.0" stylesheets="@../css/player.css">
    <top>
        <fx:include source="titleBar.fxml"/>
    </top>
    <left>
        <fx:include source="userLeft.fxml"/>
    </left>
    <center>
        <fx:include source="albumDetail.fxml"/>
    </center>
    <bottom>
        <fx:include source="playBar.fxml"/>
    </bottom>
</BorderPane>

在 Main.class 中我启动应用程序。

@SpringBootApplication
public class Main extends AbstractJavaFxApplicationSupport implements ApplicationContextAware{

    private static BorderPane root;

    @Autowired
    private ApplicationContext applicationContext;

    public static void main(String[] args) {
        launchApp(Main.class, PlayerView.class, new BlueprintSplashScreen(),args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        super.start(stage);
        stage.getIcons().add(new Image("img/music-icon32.png"));
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

   // ignore this. It's something I tried to meet my requirement.
   //I  try to use         
   //PlayerView view = applicationContext.getBean(PlayerView .class);
   //root = (BorderPane) view.getView();
   //but it throws NullPointerException dor applicationContext, it seems inject fail
    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }
}

我想动态更改 BorderPane 中的中心内容。我确实需要获取此 BorderPane,以便可以更改它。 顺便说一句,我也使用Main.showView(xxx.class),但我只是想改变中心。而不是整个舞台。 非常感谢。

最佳答案

我对spring更加熟悉了。通过使用springboot-javafx-support注释@FXMLView, View 已经注册到spring bean工厂。所以当我想使用 View 时就使用它。 使用 @Autowire @Resources 将 View 注入(inject)到您想要的位置。这样您就可以获取 View 并调用 getView() 方法来获取根 Pane 。

关于java - 我可以使用 springboot-javafx-support 从初级阶段获取根 Pane 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48237646/

相关文章:

java - 每个上下文一个实例的依赖注入(inject)

java - 我可以将 2D 变换应用于 JavaFX 8 Canvas 上的形状吗?

java - 为什么这些重新抛出的异常中的任何一个都会产生编译器错误?

java - Spring Boot kafka junit 失败

java - WebEngine 未加载以 HTML (javafx) 链接的文件

java - 输入 'JavaCompile' 属性 'options.compilerArgumentProviders.apt$0.name' 缺少输入或输出注释。升级到 Gradle 7 后出错

java - SLF4J 按标记过滤日志消息

java - Android:java.lang.RuntimeException:在 android.app.ActivityThread.installProvider

java - 如何在 Jersey 服务器中获取/注入(inject)当前的 SSLSession?

java - JScrollPane 内的 JTable : best height to disable scrollbars