I'd like to calculate the height and set the resizeWeight of a JSplitPane that may contain other JSplitPanes and other Components as well. The concept right now looks the following (warning: snippet, not a fully functional code fragment; I only need guidelines for rewriting the recursive invocations with a while-loop using accumulators, not a fully functional solution code).
splitPane.setResizeWeight(calculateComponentHeight(splitPane.getTopComponent()) / calculateNewSplitPaneHeight(splitPane));
...
private double calculateNewSplitPaneHeight(JSplitPane sp) {
return calculateComponentHeight(sp.getTopComponent()) + calculateComponentHeight(sp.getBottomComponent());
}
private double calculateComponentHeight(Component c) {
if (c instanceof JSplitPane) {
return calculateNewSplitPaneHeight((JSplitPane) c);
}
return (double) c.getHeight();
}
As I may not know the level of embeddedness of the split panes, what can be a practical approach towards resolving such recursions?
And yes, I know, splitPane.getPreferredSize().height
and splitPane.getTopComponent().getPreferredSize().height
give me the answers I need without any recursive invocations. This is question is merely here to work one's brain on recursions and loops.