Hey all, I am currently working on an assignment for Java, I need to create a couple of forms containing labels, text fields, buttons etc...
I got all the coding behind the forms done (calculations, display values etc..) and i've created a couple of "dummy" forms (didnt add ActionListener / ActionPerformed yet). Problem being is the layout of the form itself.
I've read through my notes on LayoutManager , read on the java.sun site, but alas i cannot seem to make my layout how i want it to be:
the code below for one of my dummy forms is:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class wInput extends JFrame
{
private JPanel panel = new JPanel();
private JLabel lbl_1 = new JLabel("Label 1");
private JLabel lbl_2 = new JLabel("Label 2");
private JLabel lbl_3 = new JLabel("Label 3");
private JLabel lbl_4 = new JLabel("Label 4");
private JTextField txt_1 = new JTextField(10);
private JTextField txt_2 = new JTextField(10);
private JTextField txt_3 = new JTextField(10);
private JTextField txt_4 = new JTextField(10);
private JButton btn1 = new JButton("Button");
public wInput()
{
super("Input");
setWindow();
panel.add(lbl_1);
panel.add(txt_1);
panel.add(lbl_2);
panel.add(txt_2);
panel.add(lbl_3);
panel.add(txt_3);
panel.add(lbl_4);
panel.add(txt_4);
panel.add(btn1);
add(panel);
setVisible(true);
}
private void setWindow()
{
setSize(500,300);
lbl_1.setSize(70,100);
lbl_2.setSize(70,100);
lbl_3.setSize(70,100);
lbl_4.setSize(70,100);
txt_1.setSize(70,100);
txt_2.setSize(70,100);
txt_3.setSize(70,100);
txt_4.setSize(70,100);
btn1.setSize(150,200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
At the moment the layout is something like this:
lbl1 txt1 lbl2 txt2 lbl3 txt3 lbl4 txt4
btn1
I need to set my layout something similar to this:
http://server7.pictiger.com/img/7340...rm-layout-.jpg
I played around with GridLayout, Layout(null) (which was a big mistake , heh), FlowLayout, none of those seemed to work (or probably i did not set some parameters right)
Any idea on how to set my form's layout?
Cheers.
