Java GridBagLayout标签重叠

Java GridBagLayout标签重叠,java,Java,我的最后两个标签重叠,我不知道为什么。我不认为网格中有任何重叠,我把它画了出来Right'是GridBagLayout面板的名称。如果我去掉最后两个标签,将1指定给weightx,将weighty指定给chickenCostLabel,它就会按预期的方式工作 JLabel chickenLabel = new JLabel(); chickenLabel.setText("Chicken"); gbc3.gridx = 0; gbc3.gridy = 1;

我的最后两个标签重叠,我不知道为什么。我不认为网格中有任何重叠,我把它画了出来Right'是GridBagLayout面板的名称。如果我去掉最后两个标签,将1指定给weightx,将weighty指定给chickenCostLabel,它就会按预期的方式工作

    JLabel chickenLabel = new JLabel();
    chickenLabel.setText("Chicken");
    gbc3.gridx = 0;
    gbc3.gridy = 1;
    gbc3.weighty = 0;
    gbc3.weightx = 0;
    right.add(chickenLabel, gbc3);

    chickenCountLabel = new JLabel();
    chickenCountLabel.setText("Count: ");
    gbc3.gridx = 0;
    gbc3.gridy = 2;
    gbc3.weighty = 0;
    gbc3.weightx = 0;
    right.add(chickenCountLabel, gbc3);

    chickenCostLabel = new JLabel();
    chickenCostLabel.setText("Cost: ");
    gbc3.gridx = 0;
    gbc3.gridy = 3;
    gbc3.weighty = 0;
    gbc3.weightx = 0;
    right.add(chickenCostLabel, gbc3);

    JButton chickenButton = new JButton();
    chickenButton.setPreferredSize(new Dimension(50, 50));
    gbc3.gridx = 1;
    gbc3.gridy = 1;
    gbc3.gridheight = 3;
    gbc3.weighty = 0;
    gbc3.weightx = 0;
    chickenButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            queueBuyNum.add(1);
        }
    });
    right.add(chickenButton, gbc3);

    JLabel blobLabel = new JLabel();
    blobLabel.setText("Blob");
    gbc3.gridx = 0;
    gbc3.gridy = 4;
    gbc3.weighty = 0;
    gbc3.weightx = 0;
    right.add(blobLabel, gbc3);

    blobCountLabel = new JLabel();
    blobCountLabel.setText("Count: ");
    gbc3.gridx = 0;
    gbc3.gridy = 5;
    gbc3.weighty = 1;
    gbc3.weightx = 1;
    right.add(blobCountLabel, gbc3);

您是否使用类似netbeans的ide?或者自己尝试我会建议使用netbeans,因为它非常简单,而且有更多的功能。你可以在几分钟内设计你的gui。好的,我会给它一个goI。我想你也需要为其他标签设置weightx和weighty(类似于上一个),看我运行它,标签没有重叠。也许您设置为右面板或框架的小尺寸?你能在你的代码中添加更多关于它的细节吗?