
how to add containers in form

Hi Friend,
Try this:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class FormData{
public static void main(String[] args){
JFrame f=new JFrame();
JLabel label1=new JLabel("Name: ");
JLabel label2=new JLabel("Date Of Birth: ");
JLabel label3=new JLabel("Address: ");
JLabel label4=new JLabel("Contact No: ");
final JTextField text1=new JTextField(20);
final JTextField text2=new JTextField(20);
final JTextField text3=new JTextField(20);
final JTextField text4=new JTextField(20);
JButton b=new JButton("Save");
JPanel p=new JPanel(new GridLayout(5,2));
p.add(label1);
p.add(text1);
p.add(label2);
p.add(text2);
p.add(label3);
p.add(text3);
p.add(label4);
p.add(text4);
p.add(b);
f.add(p);
f.setVisible(true);
f.pack();
}
}
For more information, visit the following :
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.