Swing中使用GridBagLayout布局的时候
调整距离边框距离
可以使用fill
属性,搭配insets
,类设置距离边框的距离
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;*/
// 当前集团 TODO
c.gridwidth = GridBagConstraints.RELATIVE;
this.rulePane.add(this.getlbGrp(), c);
c.gridwidth = GridBagConstraints.REMAINDER;
this.rulePane.add(this.getlbGrpcode(), c);
// 归零标志
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);
设置有布局的宽高
this.ruleMainPane.setPreferredSize(new Dimension(1001, 330));
GridBagLayout布局
其他的设置宽高
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);
网友评论