我有一个方法,就是向 JPanel 添加一个按钮。但是,我有一个问题,该按钮的某些属性我无法修改。
setBackground和setLocation方法根本不影响按钮。我试图将按钮移动到底部,JPannel但当我尝试设置水平对齐或位置时似乎没有发生任何事情。
public static void initButtons() {
JButton purchaseButton = new JButton();
purchaseButton.setText("Proceed to Checkout");
purchaseButton.setPreferredSize(new Dimension(200,50));
purchaseButton.setIcon(new ImageIcon("/Users/alecr/eclipse-workspace/MakingPurchases/src/shopping_cart_sprite.png"));
// set location method not working
purchaseButton.setLocation(25, 600);
JPanel firstPanel = new JPanel();
firstPanel.setBounds(25, 40, 300, 700);
firstPanel.setBackground(new java.awt.Color(90,90,100));
firstPanel.setBorder(BorderFactory.createStrokeBorder(new BasicStroke(3.0f), new Color(70,70,80)));
frame.add(firstPanel);
firstPanel.add(purchaseButton);
}
撒科打诨
相关分类