Java网格布局问题

Java网格布局问题,java,swing,jpanel,gridbaglayout,Java,Swing,Jpanel,Gridbaglayout,我在调整组合框时遇到问题,因此它更接近“波段目录”标签。如何将组合框向左移动,仅将标签旁边的5px移动。我曾尝试为我的标签设置水平插入,为我的组合框设置负片插入,但仍然不起作用 这是我的密码: public void createGUI() { main_panel = new JPanel(); main_panel.setLayout(new GridBagLayout()); GridBagConstraints gc = new GridBagConstraints()

我在调整组合框时遇到问题,因此它更接近“波段目录”标签。如何将组合框向左移动,仅将标签旁边的5px移动。我曾尝试为我的标签设置水平插入,为我的组合框设置负片插入,但仍然不起作用

这是我的密码:

public void createGUI()
{
   main_panel = new JPanel();
   main_panel.setLayout(new GridBagLayout());
   GridBagConstraints gc = new GridBagConstraints();

   label = new JLabel("Band Directory:");
   band_combobox = new JComboBox();
   members_panel = new JPanel();
   members_panel.setBorder(title);
   members_list = new JLabel();
      members_panel.add(members_list);

   gc.fill = GridBagConstraints.HORIZONTAL;
   gc.gridx = 0;
   gc.gridy = 0;
   gc.insets = new Insets(0, 0, 10, 0);
      main_panel.add(label, gc);

   gc.fill = GridBagConstraints.HORIZONTAL;
   gc.gridx = 1;
   gc.gridy = 0;
   gc.insets = new Insets(0, 0, 10, 0);
      main_panel.add(band_combobox, gc);

   gc.fill = GridBagConstraints.HORIZONTAL;
   gc.gridx = 0;
   gc.gridy = 1;
   gc.insets = new Insets(0, 0, 10, 0);
      main_panel.add(members_panel, gc);

 //more code
}

尝试调整
成员\u面板的溢出量

gc.fill = GridBagConstraints.HORIZONTAL;
gc.gridx = 0;
gc.gridy = 1;
gc.insets = new Insets(0, 0, 10, 0);
gc.gridwidth = 2; // Allows the members_panel to use 2 columns within the grid
main_panel.add(members_panel, gc);

这是一个很好的改变:通常,我会避免GrindBagLayout,而是使用其他布局管理器的多个嵌套实例。