2

我在调整组合框时遇到问题,使其更接近“乐队目录”标签。我如何将组合框向左移动,距离标签仅 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
}

在此处输入图像描述

4

1 回答 1

5

尝试调整溢出members_panel...

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);
于 2013-05-28T07:15:51.767 回答