Hi I have a (hopefully simple) question all I am trying to do is create a single JButton in the bottom center of my GUI but I don't know which layout manager to use. Am I right to assume I need to create a new JPanel (with some sort of layout) then create the JButton?? But how to make it bottom center??
Heres the code I have if it helps any critiquing of my code is most welcome
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
//import java.awt.image.*;
public class myFrame extends JFrame implements ActionListener
{
// instance variables - replace the example below with your own
private JPanel pane = new JPanel();
private JPanel pane1 = new JPanel();
private JPanel pane2 = new JPanel(new FlowLayout());
private JPanel pane3 = new JPanel(new FlowLayout());
private JButton button1,button2,button3,button4,button5,button6,
button7,button8,button9,button10,button11,button12,
button13,button14,button15,button16,button17,button18,
button19,button20,button21,button22,button23,button24,
button25,button26;
String rlabels[] = {"$1,000","$1,500","$2,000","$3,000","$5,000",
"$7,500","$10,000","$15,000","$25,000","$50,000","$75,000","$100,000","$200,000"};
String rlabels1[] = {" $0.50 "," $1 "," $2 "," $5 "," $15 "," $25 "
," $50 "," $75 "," $100 "," $150 "," $250 "," $500 "," $750 "};
private JButton[] buttons = {button1,button2,button3,button4,button5,button6,button7
,button8,button9,button10,button11,button12,button13,button14,button15,
button16,button17,button18,button19,button20,button21,button22,
button23,button24,button25,button26};
/**
* Constructor for objects of class myFrame
*/
myFrame()
{
super("My First frame");
setBounds(50,100,600,450);
Container con = this.getContentPane();
pane.setLayout(new GridLayout(13,1,0,0));
pane1.setLayout(new GridLayout(13,1,0,0));
for (int i=0;i<rlabels.length;i++){
JLabel lab = new JLabel(rlabels[i]);
JLabel lab1 = new JLabel(rlabels1[i]);
lab.setForeground(Color.white);lab1.setForeground(Color.white);
JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel p1 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
p.setBackground(Color.blue);p1.setBackground(Color.blue);
p.add(lab); p1.add(lab1);
pane.add(p);pane1.add(p1);
}
con.add("East",pane);con.add("West",pane1);
for (int i=0;i<buttons.length;i++){
buttons[i] = new JButton("Briefcase " + (i+1));
pane2.add(buttons[i]);}
pane2.setBackground(Color.white);
con.add(pane2);
// initialise instance variables
}
public void actionPerformed(ActionEvent ae)
{
// put your code here
}
public static void main(String[] args){myFrame app = new myFrame();app.setVisible(true);};
}