Easy Layout Examples


Simple Example
simple example

This java frame can be constructed with a single RowLayout. Here is the source code to prove it.
import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

import net.sf.easylayouts.*;


public class SimpleExample extends JFrame implements ActionListener
{
	private JTextField name_field;
	private JTextField abbreviation_field;
	private JTextField order_field;
	private JComboBox picture_combo;
	private JTextArea desc_field;

	private JCheckBox complete_check;
	private JCheckBox published_check;

	private JButton ok_button;
	private JButton cancel_button;
	private JButton apply_button;

    public SimpleExample()
    {
		setTitle("Terrain: Swamp");

		RowLayout layout = new RowLayout(getContentPane());

		layout.add(new JLabel("Terrain name:"), 0);
		name_field = new JTextField(20);
		layout.add(name_field, 0);

		layout.add(new JLabel("Abbreviation:"), 1);
		abbreviation_field = new JTextField(4);
		layout.add(abbreviation_field, 1);

		layout.add(new JLabel("Display order:"), 1);
		order_field = new JTextField(4);
		layout.add(order_field, 1);

		layout.add(new JLabel("Picture:"), 2);
		picture_combo = new JComboBox(getPictures());
		layout.add(picture_combo, 2);

		complete_check = new JCheckBox("Complete");
		layout.add(complete_check, 3);

		published_check = new JCheckBox("Published");
		layout.add(published_check, 3);
		
		layout.addSpring(4);

		ok_button = new JButton("OK");
		layout.add(ok_button, 4);
		ok_button.addActionListener(this);

		cancel_button = new JButton("Cancel");
		layout.add(cancel_button, 4);
		cancel_button.addActionListener(this);

		apply_button = new JButton("Apply");
		layout.add(apply_button, 4);
		apply_button.addActionListener(this);
    }

	public void actionPerformed(ActionEvent event)
	{
		if (event.getSource() == ok_button)
		{
			dispose();
		}
		else if (event.getSource() == cancel_button)
		{
			dispose();
		}
		else if (event.getSource() == apply_button)
		{
		}
	}


	private Object[] getPictures()
	{
	    Object[] picts = new Object[3];

		picts[0] = "water";
		picts[1] = "rock";
		picts[2] = "swamp";

		return picts;
	}
	
	public static void main(String[] args)
	{
		SimpleExample frame = new SimpleExample();			
		frame.pack();
		frame.show();
	}
}