我在调整组合框时遇到问题,因此它更接近'band directory'标签。如何将组合框向左移动,除标签外仅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
}
答案 0 :(得分: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);