- I develop one javafx application.
- In my application there are two scenes and one stage.
- In application the height and width for both scenes are same or constant.
- so as per my research the height and width for scene remain constant which mention in the constructor but the scene adjust itself with height and width of stage.
- when i lunch application with the height and width of stage which is different than the constant height and width of scene then scene adjust with stage.
but when at the run time when i apply the 2nd scene then scene is not adjust with height and width of stage.the height and width of scene remain constant.
so any solution?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
I know this is an old topic, but this (bug?) still persists in Java7u75.
I ran into the same issue... the solution offered by shambhu above does work, but results in a visible "window switching" effect:
I found that the following code solves the problem (gets the stage to "refresh") without any visible effects:
As I understand the problem above posted. I think the stage is good enough to set the preferred height and width as per the listener get the newer request to apply on the windows size. But it has some limitations, if you maximize or minimize the javaFX screen and will try to navigate to other screen then other screen will be having same window size but the scene content will distorted into the default height and width of it, e.g take a login and home scene in javafx (all scene is screated with fxml). Login.fxml is initialized by its controller. As you have mentioned that scene is initialized in constructor, so it must be the controller of the related fxml(as of now FXML is tight coupled with controller). You are going to set the scene size(height & width) in constructor itself.
1.) LoginController for login.fxml
2.) Same for HomeController --
3.) Main class
Just try to put Stage.hide() before Stage.show() in every controller. I hope this will help you out.
That is because the Stage adapts its size to the scene, unless explicitly instructed diferently...
To here is one solution:
And a sample application: