我在調整我的組合框時遇到了問題,所以它更接近'band目錄'標籤。如何將組合框移動到左側,除標籤外僅爲5px。我曾嘗試爲我的標籤設置水平插入,爲我的組合框設置負插入,但仍然無法使用。Java gridbaglayout問題
這裏是我的代碼:
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
}
就個人而言,我會避免GrindBagLayout,而使用多個嵌套實例的其他佈局經理。 –