Can I get the root Pane from the primary stage?
Closed this issue · 3 comments
Firstly thanks for contribute this awesome project.
I have a main page call player.fxml
which is a BorderPane.Something like this
<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>
In the Main.class I launch the app.
@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;
}
}
I want to change the center content in the BorderPane dynamically.I really need to get this BorderPane so I can change it.
BTW,I also use Main.showView(xxx.class),but I just want to change the center.Not a whole stage.
Thanks a lot advanced.
This link will help with what you are asking for:
https://github.com/roskenet/spring-javafx-examples/tree/master/part_7/src/main/java/example
The day before I not very familiar with the spingboot anotation so I can confused.Now I know I get use spring factory(anotation) to get the specify view so I can invoke the getView() method,getting the view root pane.
Problem seems to be solved...
Closed for now.