Swing中使用GridBagLayout布局的時(shí)候
調(diào)整距離邊框距離
可以使用fill
屬性,搭配insets
,類設(shè)置距離邊框的距離
this.rulePane = new UIPanel();
this.rulePane.setName("rulePane");
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
this.rulePane.setLayout(gridbag);
c.fill = GridBagConstraints.BOTH;
c.ipadx = 18;
c.insets = new Insets(20, 10, 2, 400);
/*c.anchor = GridBagConstraints.NORTH;
c.weightx = 2;
c.weighty = 1;*/
// 當(dāng)前集團(tuán) TODO
c.gridwidth = GridBagConstraints.RELATIVE;
this.rulePane.add(this.getlbGrp(), c);
c.gridwidth = GridBagConstraints.REMAINDER;
this.rulePane.add(this.getlbGrpcode(), c);
// 歸零標(biāo)志
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(2, 10, 2, 400);
c.gridwidth = GridBagConstraints.RELATIVE;
this.rulePane.add(this.getlblResetFlag(), c);
c.gridwidth = GridBagConstraints.REMAINDER;
this.rulePane.add(this.getcbbResetFlag(), c);
設(shè)置有布局的寬高
this.ruleMainPane.setPreferredSize(new Dimension(1001, 330));
GridBagLayout布局
其他的設(shè)置寬高
this.ruleTitlePane = new UIPanel();
this.ruleTitlePane.setName("ruleTitlePane");
this.ruleTitlePane.setBorder(new BorderCustomerLine());
this.ruleTitlePane.setLayout(new GridLayout());
this.ruleTitlePane.setBackground(new Color(204, 204, 204));
//Jack
this.ruleTitlePane.setBounds(24, 29, 970, 32);
this.ckbPrefix = new UICheckBox();
this.ckbPrefix.setName("ckbPrefix");
this.ckbPrefix.setText("");
this.ckbPrefix.setHorizontalAlignment(SwingConstants.CENTER);
//Jack
this.ckbPrefix.setBounds(23, 67, 122, 22);