SpringLayout

Previous     Next     slt.java     SLT.java     Home     Package

import java.awt.*;
import javax.swing.*;

public class SLT extends JFrame {
   JLabel label;
   JTextField parms;
   JTextArea text;
   JScrollPane pane;
   JButton button1, button2;

   public SLT () {
      // Some constants
      String WEST = SpringLayout.WEST;
      String EAST = SpringLayout.EAST;
      String NORTH = SpringLayout.NORTH;
      String SOUTH = SpringLayout.SOUTH;

      SpringLayout layout = new SpringLayout();
      setLayout(layout);
      add(label = new JLabel("Label: "));
      add(parms = new JTextField("Text field", 15));
      add(pane = new JScrollPane(text = new JTextArea(12,30)));
      add(button1 = new JButton("A Big Bony Button"));
      add(button2 = new JButton("A Beautiful Big Bony Button"));

      SpringLayout.Constraints lcons = layout.getConstraints(label);
      lcons.setX(Spring.constant(5));
      lcons.setY(Spring.constant(5));
      layout.putConstraint(WEST, parms, 5, EAST, label);
      layout.putConstraint(NORTH, parms, 5, NORTH, this);
      SpringLayout.Constraints tcons = layout.getConstraints(pane);
      tcons.setX(Spring.constant(100));
      tcons.setY(Spring.constant(50));
      layout.putConstraint(NORTH, button1, 60, NORTH, pane);
      layout.putConstraint(WEST, button1, 20, WEST, this);
      layout.putConstraint(NORTH, button2, 60, NORTH, text);
      layout.putConstraint(WEST, button2, 20, WEST, this);
      pack();
   }
}