java which layout manager suitable for this task?

后端 未结 4 1039
星月不相逢
星月不相逢 2021-01-13 17:51

I have a JPanel parent with 3 JPanel children inside. They all currently make use of GridLayout and together represent a UML class. Problem is that when I add a new attribu

4条回答
  •  清酒与你
    2021-01-13 18:11

    You can use a GridBagLayout for this. I think what worked for me was

    • add a fourth sub-panel to the top panel
    • set the weighty for the top three panels to 0
    • set the weighty for the bottom (new) panel to 1
    • depending on what technique you are using to render the text in the sub-panels, you may need to set the preferred size of sub-panels explicitly.
    • when you add new items to the sub-panels, you'll need to invalidate and re-layout the whole thing.

提交回复
热议问题