GridBagLayout panels alignment

后端 未结 7 1570
北荒
北荒 2020-12-07 01:38

I have a little issue with the GridBag Layout Manager. I am trying to display 9 panels like this:

\"Ideal

7条回答
  •  旧巷少年郎
    2020-12-07 02:00

    I never been a big fan of GridBagLayout. So for me I would break your GUI down into multiple panels and would probably use multiple GridLayout to achieve what you want. Something like:

    JPanel top = new JPanel( new GridLayout(0, 5) );
    top.add(s1);
    JPanel s23 = new JPanel( new GridLayout(2, 0) );
    s23.add(s2);
    s23.add(s3);
    top.add(s23);
    ...
    
    JPanel bottom = new JPanel( new GridLayout(0, 2) );
    bottom.add(s8);
    bottom.add(s9);
    
    JPanel main = new JPanel( appropriate layout manager );
    main.add(top);
    main.add(bottom);
    

提交回复
热议问题