"however I need the buttons to appear on the bottom of the JPanel
."
This add(go,BorderLayout.SOUTH);
won't work, unless you set the layout of the JPanel
to BorderLayout
. It has a default FlowLayout
that will leave the the button at the top.
setLayout(new BorderLayout());
Looking your previous question, you have a start
button too. Not sure where you want to place that one. So here are option.
If you want both buttons at the bottom, wrap them in another JPanel
and add that JPanel
to the main JPanel
using BorderLayout.SOUTH
If you want start
at the top and go
at the bottom, then BorderLayout.NORTH
for start
and BorderLayout.SOUTH
for go
Which ever way you go, don't forget to set the layout of the class JPanel
EDIT
public class BallPanel extends JPanel {
public BallPanel() {
JPanel panel = new JPanel();
JButton go = new JButton("GO");
JButton stop = new JButton("STOP");
panel.add(go);
panel.add(stop);
setLayout(new BorderLayout());
add(panel, BorderLayout.SOUTH);
}
}