문제

I have a Java Swing GUI where the top level layout manager is BorderLayout. I'd like it so that when the user resizes my GUI below the preferred size the center region can't be resized any smaller (or at least takes precedence in resizing) and the north/south regions become smaller.

The way it's working right now is my north and south panels are taking precedence and blowing away my center region first. I've tried setting a minimum size on the center panel once it has all of its components added to it

centerPanel.setMinimumSize(centerPanel.getPreferredSize());

but that isn't working for me. It's still the first region to minimize on a resize.

도움이 되었습니까?

해결책

Maybe a BoxLayout will work. Box layout will respect the minimum size of a component. See the section from the Swing tutorial on How to Use Box Layout for more information.

다른 팁

I don't think anything simpler than GridBagLayout will serve. BorderLayout is not good about honoring minimum sizes.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top