I'm trying to create a mini form, that suppose to look like this:
So far I got this:
The problem is that I need to have this gap from the left, so that my form will be at the center, but I don't know how to achieve this.
My code:
public class Person extends ClubAbstractEntity
{
protected String id;
protected String name;
protected String surname;
protected String tel;
public Person(String id,String name,String surname,String tel)
{
this.id=id;
this.name=name;
this.surname=surname;
this.tel=tel;
JLabel[] labels={new JLabel("Id", JLabel.RIGHT),new JLabel("Name", JLabel.RIGHT),new JLabel("Surname", JLabel.RIGHT),new JLabel("Tel", JLabel.RIGHT)};
JTextField[] textFields=new JTextField[labels.length];
JPanel container=new JPanel();
container.setLayout(new BorderLayout());
JPanel labelPanel = new JPanel(new GridLayout(labels.length, 1));
JPanel fieldPanel = new JPanel(new GridLayout(labels.length, 1));
container.add(labelPanel, BorderLayout.WEST);
container.add(fieldPanel, BorderLayout.CENTER);
for(int i=0;i<labels.length;i++)
{
//container.add(labels[i]);
textFields[i]=new JTextField(30);
labels[i].setLabelFor(textFields[i]);
labelPanel.add(labels[i]);
JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
p.add(textFields[i]);
fieldPanel.add(p);
//container.add(textFields[i]);
}
setSize(450,220);
addToCenter(container);
}
It uses its parent (a class that extends JFrame) method called addToCenter which gets a GUI component and add it to the center.
protected void addToCenter(Component guiComponent)
{
add(guiComponent,BorderLayout.CENTER);
}

