I have a method that is just adding a button to a JPanel. I have a problem however, where there are some properties of this button that I cannot modify.
setBackground
and setLocation
method don't affect the button at all. I'm trying to move the button to the bottom of the JPannel
but nothing seems to happen when I try setting the horizontal alignment or location.
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);
}