I have a TabPane with multiple tabs inside a dialog . Within each of the tabs sits a pane with a different default size. I don't want to set the min, max, or pref size as I want my application to layout the pane automatically and hence deal effectively with different DPI screens. The issue is that I want to resize tab pane and hence dialog every time a select a tab, instead of the tab pane simply being the size of the biggest content pane. So for example if 'Tab 1' has a content pane with a default layout which ends up making it 300x300 pixels then on clicking 'Tab 1' I want the TabPane and then dialog to resize to 300x300.
e.g something like
private void addTabListeners(){
for (int i=0; i<pamTabbedPane.getTabs().size(); i++){
final int n=i;
pamTabbedPane.getTabs().get(i).setOnSelectionChanged((value)->{
System.out.println("Tab selected "+pamTabbedPane.getTabs().get(n).getText());
/**
* Find default size of content pane
*/
double defualtHWidth=pamTabbedPane.getTabs().get(n).getContent().....
double defualtHeight=pamTabbedPane.getTabs().get(n).getContent().....
/*******************************/
pamTabbedPane.setPrefSize(defualtHWidth, defualtHeight);
Stage stage = (Stage) pamTabbedPane.getScene().getWindow();
stage.sizeToScene();
});
}
}
This is a problem I come across quite a lot in different layout problems so any advice on how to approach it without resorting to manually setting size would be much appreciated.