Here is some information I found. Keep in mind that I'm still quite an amateur programmer.
I copied your code and tried to find a solution on how to get around this problem.
As I noticed, some strange things happened with the tab - the contents of the tab suddenly turned white, the methods that return the borders will always return the same value, and sizeToSceneMethod () just does it - sets the width and the height of the scene in accordance with what is inside it.
Now, having noticed strange things that I have broken through google, find this error, which says that it has not yet been resolved for several years.
There I found a piece of code that works, but it has this problem - the tab is removed and added every time, and you can see it visually
private static final void changeTabPaneSize(final TabPane tabPane) { final int index = tabPane.getSelectionModel().getSelectedIndex(); if (index < 0 || tabPane.getTabs().isEmpty()) { return; } if (tabPane.getTabs().size() == 1) { final Tab tab = tabPane.getTabs().remove(0); tabPane.getTabs().add(tab); } else if (tabPane.getTabs().size() > 1 && index == 0) { tabPane.getSelectionModel().select(1); } else if (tabPane.getTabs().size() > 1 && index != 0) { tabPane.getSelectionModel().select(1); } tabPane.getSelectionModel().select(index); }
Using this method and then calling sizeToScene worked:
changeTabPaneSize(tabbedPane); primaryStage.sizeToScene();
Also, the best option would be to set the scene size manually, even if this kind of smells, although it works:
primaryStage.sizeToScene(); double constantFoundByTrialAndError = 70; primaryStage.setHeight(mainPane.getHeight()+constantFoundByTrialAndError);
Edit: Now I noticed that I answered a 2-year question.
source share