gpt4 book ai didi

Java gridbaglayout问题

转载 作者:行者123 更新时间:2023-11-30 06:24:31 25 4
gpt4 key购买 nike

我在调整组合框时遇到问题,因此它更接近“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
}

enter image description here

最佳答案

尝试调整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);

关于Java gridbaglayout问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16785901/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com