BorderLayout Help

Hey I am having some trouble with the Layout which my game will be in. I am fairly new to Java programming. I cannot get the layout to work for some reason. :frowning:

import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.BorderLayout;

class GUI {
	
	public static void main(String args[]) {
		JFrame frame;
		Container contentPane;
		JTextField textfield;
		String load;
		String ngame;
		String pause;
		JButton button;
		JButton button2;
		JButton button3;
		ImageIcon soon;
		BorderLayout layout;
		JLabel label;
		
		frame = new JFrame();
		frame.setTitle("Game");
		
		load = "Load Game";
		ngame = "New Game";
		pause = "Pause";
		button = new JButton(load);
		button2 = new JButton(ngame);
		button3 = new JButton(pause);
		soon = new ImageIcon("commabunnysoon.jpg");
		layout = new BorderLayout();
		label = new JLabel(soon);
		contentPane = frame.getContentPane();
		
		contentPane.add(label, BorderLayout.CENTER);
		contentPane.add(button, BorderLayout.PAGE_END);
		contentPane.add(button2, BorderLayout.PAGE_END);
		contentPane.add(button3, BorderLayout.PAGE_END);
		contentPane.setLayout(layout);
		
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
}

What I am trying to do is, make it so that the image comes up on top and the buttons go on the bottom.

Thanks.

Two things:

  1. Set the layout before you start adding components to the content pane

  2. If you try to add more than one component in the same place only the last one will show up. You should add your buttons to a separate JPanel then add the JPanel to the content pane

Cheers,
Brett