Scene is off-centered on stage after switching from a different scene





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I've tried numerous things to make this scene fit the stage (as other scenes in my application do) but I can't figure it out.



I'm currently using buttons and controllers to switch scenes, with the aim of maintaining an MVC format, so I'm using the line stage.setScene(new Scene(root pane), desired width, desired height).



However the flicker that comes with switching scenes ruins the seamlessness of my application.



I have tried other suggestions like stage.centerOnScreen() but this seems to shift the whole stage out of view (cuts half the stage off), I have also tried stage.sizeToScreen(), however this seemed to make no difference.



Ideally, I'd like to use stage.getScene().setRoot(pane), but the scene seems to change size or creates a white border instead of resizing the stage to fit the scene (as shown).



If I hadn't made myself clear thus far, I am trying to get the scene to fit the stage. The scene's root pane is the desired size when it is set as the root, but for some reason the scene changes size.



This is how I'd like the scene to fit the stage (this is scene 1)



enter image description here



but this is what happens when I change the root of the scene to the next page.



enter image description here



So, ideally I'm looking for a way to use setRoot(pane), getting the scene to fit the stage or use setScene(scene) without the flickering.



Code examples:



In one of my controllers, I have this (working as intended):



public void handle(MouseEvent event) {
if (event.getSource() instanceof Button) {
Button sourceButton = (Button)event.getSource();
Stage primaryStage = (Stage ((Node)event.getSource()).getScene().getWindow();

if (sourceButton.getId().equals("back-button")) {
primaryStage.getScene().setRoot(view.getWelcomePane());
}
}
}


In the view:



public Pane getWelcomePane() {
return new BorderPane(bpWelcomeMain); // bpWelcomeMain is the border pane that contains all the page components
}


In the other controller, when it appears how I want I have to use this (but this produces flickering):



public void handle(MouseEvent event) {

if (event.getSource() instanceof Button) {

Button clickedButton = (Button)event.getSource();
Stage primaryStage = (Stage)((Node)event.getSource()).getScene().getWindow();

if (clickedButton.getId().equals("create-button")) {
primaryStage.setScene(view.getCreateScene());
}
}


In the view:



public Scene getCreateScene() {
return new Scene(bpCreateMain, 1500, 750); // bpCreateMain is the border pane that contains all the page components
}


However I would like to use .setRoot() instead of setScene() as shown in the first example to remove the flickering but also need to have it appear as intended (so I would like to use my getCreatePane() method in this view - similar to getWelcomePane() instead of getCreateScne()), the methods are practically the same so I am unsure why it is not working.










share|improve this question

























  • Possible duplicate of JavaFX equivalent of Swing's pack()

    – Vince Emigh
    Nov 16 '18 at 23:27











  • I've also tried sizeToScreen(), nothing changes.

    – JIrv
    Nov 16 '18 at 23:32






  • 3





    @Jlrv Please provide a MVCE that reproduces the issue

    – Vince Emigh
    Nov 16 '18 at 23:44











  • I think that code (mcve ) would have been clearer and shorter than the attempt to describe it.

    – c0der
    Nov 17 '18 at 4:33


















1















I've tried numerous things to make this scene fit the stage (as other scenes in my application do) but I can't figure it out.



I'm currently using buttons and controllers to switch scenes, with the aim of maintaining an MVC format, so I'm using the line stage.setScene(new Scene(root pane), desired width, desired height).



However the flicker that comes with switching scenes ruins the seamlessness of my application.



I have tried other suggestions like stage.centerOnScreen() but this seems to shift the whole stage out of view (cuts half the stage off), I have also tried stage.sizeToScreen(), however this seemed to make no difference.



Ideally, I'd like to use stage.getScene().setRoot(pane), but the scene seems to change size or creates a white border instead of resizing the stage to fit the scene (as shown).



If I hadn't made myself clear thus far, I am trying to get the scene to fit the stage. The scene's root pane is the desired size when it is set as the root, but for some reason the scene changes size.



This is how I'd like the scene to fit the stage (this is scene 1)



enter image description here



but this is what happens when I change the root of the scene to the next page.



enter image description here



So, ideally I'm looking for a way to use setRoot(pane), getting the scene to fit the stage or use setScene(scene) without the flickering.



Code examples:



In one of my controllers, I have this (working as intended):



public void handle(MouseEvent event) {
if (event.getSource() instanceof Button) {
Button sourceButton = (Button)event.getSource();
Stage primaryStage = (Stage ((Node)event.getSource()).getScene().getWindow();

if (sourceButton.getId().equals("back-button")) {
primaryStage.getScene().setRoot(view.getWelcomePane());
}
}
}


In the view:



public Pane getWelcomePane() {
return new BorderPane(bpWelcomeMain); // bpWelcomeMain is the border pane that contains all the page components
}


In the other controller, when it appears how I want I have to use this (but this produces flickering):



public void handle(MouseEvent event) {

if (event.getSource() instanceof Button) {

Button clickedButton = (Button)event.getSource();
Stage primaryStage = (Stage)((Node)event.getSource()).getScene().getWindow();

if (clickedButton.getId().equals("create-button")) {
primaryStage.setScene(view.getCreateScene());
}
}


In the view:



public Scene getCreateScene() {
return new Scene(bpCreateMain, 1500, 750); // bpCreateMain is the border pane that contains all the page components
}


However I would like to use .setRoot() instead of setScene() as shown in the first example to remove the flickering but also need to have it appear as intended (so I would like to use my getCreatePane() method in this view - similar to getWelcomePane() instead of getCreateScne()), the methods are practically the same so I am unsure why it is not working.










share|improve this question

























  • Possible duplicate of JavaFX equivalent of Swing's pack()

    – Vince Emigh
    Nov 16 '18 at 23:27











  • I've also tried sizeToScreen(), nothing changes.

    – JIrv
    Nov 16 '18 at 23:32






  • 3





    @Jlrv Please provide a MVCE that reproduces the issue

    – Vince Emigh
    Nov 16 '18 at 23:44











  • I think that code (mcve ) would have been clearer and shorter than the attempt to describe it.

    – c0der
    Nov 17 '18 at 4:33














1












1








1








I've tried numerous things to make this scene fit the stage (as other scenes in my application do) but I can't figure it out.



I'm currently using buttons and controllers to switch scenes, with the aim of maintaining an MVC format, so I'm using the line stage.setScene(new Scene(root pane), desired width, desired height).



However the flicker that comes with switching scenes ruins the seamlessness of my application.



I have tried other suggestions like stage.centerOnScreen() but this seems to shift the whole stage out of view (cuts half the stage off), I have also tried stage.sizeToScreen(), however this seemed to make no difference.



Ideally, I'd like to use stage.getScene().setRoot(pane), but the scene seems to change size or creates a white border instead of resizing the stage to fit the scene (as shown).



If I hadn't made myself clear thus far, I am trying to get the scene to fit the stage. The scene's root pane is the desired size when it is set as the root, but for some reason the scene changes size.



This is how I'd like the scene to fit the stage (this is scene 1)



enter image description here



but this is what happens when I change the root of the scene to the next page.



enter image description here



So, ideally I'm looking for a way to use setRoot(pane), getting the scene to fit the stage or use setScene(scene) without the flickering.



Code examples:



In one of my controllers, I have this (working as intended):



public void handle(MouseEvent event) {
if (event.getSource() instanceof Button) {
Button sourceButton = (Button)event.getSource();
Stage primaryStage = (Stage ((Node)event.getSource()).getScene().getWindow();

if (sourceButton.getId().equals("back-button")) {
primaryStage.getScene().setRoot(view.getWelcomePane());
}
}
}


In the view:



public Pane getWelcomePane() {
return new BorderPane(bpWelcomeMain); // bpWelcomeMain is the border pane that contains all the page components
}


In the other controller, when it appears how I want I have to use this (but this produces flickering):



public void handle(MouseEvent event) {

if (event.getSource() instanceof Button) {

Button clickedButton = (Button)event.getSource();
Stage primaryStage = (Stage)((Node)event.getSource()).getScene().getWindow();

if (clickedButton.getId().equals("create-button")) {
primaryStage.setScene(view.getCreateScene());
}
}


In the view:



public Scene getCreateScene() {
return new Scene(bpCreateMain, 1500, 750); // bpCreateMain is the border pane that contains all the page components
}


However I would like to use .setRoot() instead of setScene() as shown in the first example to remove the flickering but also need to have it appear as intended (so I would like to use my getCreatePane() method in this view - similar to getWelcomePane() instead of getCreateScne()), the methods are practically the same so I am unsure why it is not working.










share|improve this question
















I've tried numerous things to make this scene fit the stage (as other scenes in my application do) but I can't figure it out.



I'm currently using buttons and controllers to switch scenes, with the aim of maintaining an MVC format, so I'm using the line stage.setScene(new Scene(root pane), desired width, desired height).



However the flicker that comes with switching scenes ruins the seamlessness of my application.



I have tried other suggestions like stage.centerOnScreen() but this seems to shift the whole stage out of view (cuts half the stage off), I have also tried stage.sizeToScreen(), however this seemed to make no difference.



Ideally, I'd like to use stage.getScene().setRoot(pane), but the scene seems to change size or creates a white border instead of resizing the stage to fit the scene (as shown).



If I hadn't made myself clear thus far, I am trying to get the scene to fit the stage. The scene's root pane is the desired size when it is set as the root, but for some reason the scene changes size.



This is how I'd like the scene to fit the stage (this is scene 1)



enter image description here



but this is what happens when I change the root of the scene to the next page.



enter image description here



So, ideally I'm looking for a way to use setRoot(pane), getting the scene to fit the stage or use setScene(scene) without the flickering.



Code examples:



In one of my controllers, I have this (working as intended):



public void handle(MouseEvent event) {
if (event.getSource() instanceof Button) {
Button sourceButton = (Button)event.getSource();
Stage primaryStage = (Stage ((Node)event.getSource()).getScene().getWindow();

if (sourceButton.getId().equals("back-button")) {
primaryStage.getScene().setRoot(view.getWelcomePane());
}
}
}


In the view:



public Pane getWelcomePane() {
return new BorderPane(bpWelcomeMain); // bpWelcomeMain is the border pane that contains all the page components
}


In the other controller, when it appears how I want I have to use this (but this produces flickering):



public void handle(MouseEvent event) {

if (event.getSource() instanceof Button) {

Button clickedButton = (Button)event.getSource();
Stage primaryStage = (Stage)((Node)event.getSource()).getScene().getWindow();

if (clickedButton.getId().equals("create-button")) {
primaryStage.setScene(view.getCreateScene());
}
}


In the view:



public Scene getCreateScene() {
return new Scene(bpCreateMain, 1500, 750); // bpCreateMain is the border pane that contains all the page components
}


However I would like to use .setRoot() instead of setScene() as shown in the first example to remove the flickering but also need to have it appear as intended (so I would like to use my getCreatePane() method in this view - similar to getWelcomePane() instead of getCreateScne()), the methods are practically the same so I am unsure why it is not working.







java css javafx scene stage






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 '18 at 14:12







JIrv

















asked Nov 16 '18 at 23:22









JIrvJIrv

112




112













  • Possible duplicate of JavaFX equivalent of Swing's pack()

    – Vince Emigh
    Nov 16 '18 at 23:27











  • I've also tried sizeToScreen(), nothing changes.

    – JIrv
    Nov 16 '18 at 23:32






  • 3





    @Jlrv Please provide a MVCE that reproduces the issue

    – Vince Emigh
    Nov 16 '18 at 23:44











  • I think that code (mcve ) would have been clearer and shorter than the attempt to describe it.

    – c0der
    Nov 17 '18 at 4:33



















  • Possible duplicate of JavaFX equivalent of Swing's pack()

    – Vince Emigh
    Nov 16 '18 at 23:27











  • I've also tried sizeToScreen(), nothing changes.

    – JIrv
    Nov 16 '18 at 23:32






  • 3





    @Jlrv Please provide a MVCE that reproduces the issue

    – Vince Emigh
    Nov 16 '18 at 23:44











  • I think that code (mcve ) would have been clearer and shorter than the attempt to describe it.

    – c0der
    Nov 17 '18 at 4:33

















Possible duplicate of JavaFX equivalent of Swing's pack()

– Vince Emigh
Nov 16 '18 at 23:27





Possible duplicate of JavaFX equivalent of Swing's pack()

– Vince Emigh
Nov 16 '18 at 23:27













I've also tried sizeToScreen(), nothing changes.

– JIrv
Nov 16 '18 at 23:32





I've also tried sizeToScreen(), nothing changes.

– JIrv
Nov 16 '18 at 23:32




3




3





@Jlrv Please provide a MVCE that reproduces the issue

– Vince Emigh
Nov 16 '18 at 23:44





@Jlrv Please provide a MVCE that reproduces the issue

– Vince Emigh
Nov 16 '18 at 23:44













I think that code (mcve ) would have been clearer and shorter than the attempt to describe it.

– c0der
Nov 17 '18 at 4:33





I think that code (mcve ) would have been clearer and shorter than the attempt to describe it.

– c0der
Nov 17 '18 at 4:33












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346642%2fscene-is-off-centered-on-stage-after-switching-from-a-different-scene%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346642%2fscene-is-off-centered-on-stage-after-switching-from-a-different-scene%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine