Java GridBagLayout未将按钮锚定到页面\结尾
我从这个网站上得到了一个不同的答案,这个家伙也有同样的问题,但我的按钮仍然没有固定到底部。有什么想法吗Java GridBagLayout未将按钮锚定到页面\结尾,java,swing,anchor,gridbaglayout,Java,Swing,Anchor,Gridbaglayout,我从这个网站上得到了一个不同的答案,这个家伙也有同样的问题,但我的按钮仍然没有固定到底部。有什么想法吗 import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOExcep
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
public class InstructionsPanel {
JComponent InstructionsPanel() throws IOException {
JComponent iPanel = new JLabel(new ImageIcon(ImageIO.read(new File("res/FinalBG.png"))));
iPanel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
BufferedImage button1icon = ImageIO.read(new File("res/MainMenu.png"));
JButton button1 = new JButton("",new ImageIcon(button1icon));
gbc = new GridBagConstraints();
iPanel.add(button1);
gbc.weighty = 1.0;
gbc.gridx = 0;
gbc.anchor = GridBagConstraints.PAGE_END;
button1.setBorder(BorderFactory.createEmptyBorder());
//button1.setContentAreaFilled(false);
return iPanel;
}
}
任何帮助都将不胜感激,谢谢 在添加
JButton
时以及在定义它们之后,使用gridbagstraints
gbc
iPanel.add(button1, gbc);
阅读