例如,我在网格布局中有 3x3 组件,我希望它们都是标签,但是由于我有一些填充,我希望我的标签位于它们的单元格的中心。但我似乎无法管理它...
部分相关代码:
panel = new JPanel();
GridBagLayout gridBag = new GridBagLayout();
panel.setLayout(gridBag);
panel.setSize(new Dimension(30, 400));
GridBagConstraints c = new GridBagConstraints()
JLabel lab = new JLabel("proba");
lab.setBorder(outline);
c.fill = GridBagConstraints.BOTH;
c.gridx =2; c.gridy=2; c.ipady = 10; c.ipadx=10;
c.ipadx=100; panel.add(lab,c);