Hi steve this is the code i developed
actually i want the
"Permannet staff Tracker" to be in the top of the screen(centre aligned)
All the labels and textfield shud be in the centre
All the buttons at the bottom of the screen which i couldnt make it.. plz help me out .. if am not really bugging
GridBagConstraints c31=new GridBagConstraints();
pane_cli=new JPanel(new GridBagLayout());
c31.insets=new Insets(15,15,15,15);
c31.insets=new Insets(5,5,5,5);
c31.anchor = GridBagConstraints.NORTH;
c31.anchor = GridBagConstraints.SOUTH;
title_lab=new JLabel("Permanent Staff Tracker");
title_lab.setFont(fon);
title_lab.setForeground(Color.black);
c31.weightx =0.3;
c31.gridx=0;
c31.gridy=0;
pane_cli.add(title_lab,c31);
clid_lab= new JLabel("Client ID");
c31.gridx=0;
c31.gridy=1;
pane_cli.add(clid_lab,c31);
clid_tex= new JTextField(20);
c31.gridx=1;
c31.gridy=1;
c31.anchor = GridBagConstraints.SOUTH;
pane_cli.add(clid_tex,c31);
cliname_lab= new JLabel("Client Name");
c31.gridx=0;
c31.gridy=2;
pane_cli.add(cliname_lab,c31);
cliname_tex= new JTextField(20);
c31.gridx=1;
c31.gridy=2;
pane_cli.add(cliname_tex,c31);
cliadd_lab= new JLabel("Client Address");
c31.gridx=0;
c31.gridy=3;
pane_cli.add(cliadd_lab,c31);
cliadd_tex= new JTextArea(3,24);
c31.gridx=1;
c31.gridy=3;
jscroll=new JScrollPane(cliadd_tex);
pane_cli.add(jscroll,c31);
cliloc_lab= new JLabel("Client Location");
c31.gridx=0;
c31.gridy=4;
pane_cli.add(cliloc_lab,c31);
cliloc_tex= new JTextField(20);
c31.gridx=1;
c31.gridy=4;
pane_cli.add(cliloc_tex,c31);
hrcontact_lab= new JLabel("HR Contact");
c31.gridx=0;
c31.gridy=5;
pane_cli.add(hrcontact_lab,c31);
hrcontact_tex= new JTextField(20);
c31.gridx=1;
c31.gridy=5;
pane_cli.add(hrcontact_tex,c31);
login_button= new JButton("SUBMIT");
c31.gridx=1;
c31.gridy=7;
pane_cli.add(login_button,c31);
update_button= new JButton("UPDATE");
c31.gridx=2;
c31.gridy=7;
pane_cli.add(update_button,c31);
delete_button= new JButton("DELETE");
c31.gridx=3;
c31.gridy=7;
pane_cli.add(delete_button,c31);
There is not that much wrong with it. Btw. you should use the code-tag to make the code better readable.
> c31.insets=new Insets(15,15,15,15);
> c31.insets=new Insets(5,5,5,5);
> c31.anchor = GridBagConstraints.NORTH;
> c31.anchor = GridBagConstraints.SOUTH;
Assigning twice does not make sense, as the last assignment overrides the first. And you actually do not want NORTH or SOUTH anchoring. I will add the missing assignments below:> title_lab=new JLabel("Permanent Staff Tracker");
> title_lab.setFont(fon);
> title_lab.setForeground(Color.black);
> c31.weightx =0.3;
> c31.gridx=0;
> c31.gridy=0;
c31.anchor=GridBagConstraints.CENTER; // centers the title
c31.gridwidth=GridBagConstraints.REMAINDER; // spans over all cells
> pane_cli.add(title_lab,c31);
>
> clid_lab= new JLabel("Client ID");
> c31.gridx=0;
> c31.gridy=1;
c31.anchor=GridBagConstraints.WEST; // left align from now on
c31.gridwidth=1; // only take one cell per label and field from now on
> pane_cli.add(clid_lab,c31);
With the buttons at the bottom there are two solutions: make all fields span over three cells or pack the buttons into a new JPanel and add the panel to the pane. The latter is much nicer, as it is independent from the number of cells used before. The additional panel would look somewhat like this:buttonPanel = new JPanel();
login_button= new JButton("SUBMIT");
buttonPanel.add(login_button);
update_button= new JButton("UPDATE");
buttonPanel.add(update_button);
delete_button= new JButton("DELETE");
buttonPanel.add(delete_button);
c31.gridx=1;
c31.gridy=7;
pane_cli.add(buttonPanel, c31);