質問

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