javaswingresizesplitpane

Java resizing window including a JSplitPane : fixed size panel?


I have a JSplitpane in my software and two JPanels inside it, and I would like the height of the divider to ajust with the screen resize

Heres what happen when I resize :

SplitPane

I have been looking everywhere for this and I know it must be easy to fix but I could not find it.


Solution

  • Link to the API/Method

    Required code :

    splitPane.setResizeWeight(1);

    Explanation :

    A value of 0, the default, indicates the right/bottom component gets all the extra space (the left/top component acts fixed), where as a value of 1 specifies the left/top component gets all the extra space (the right/bottom component acts fixed). Specifically, the left/top component gets (weight * diff) extra space and the right/bottom component gets (1 - weight) * diff extra space.