Use a SpringLayout to layout controls - Java Swing

Java examples for Swing:SpringLayout

Description

Use a SpringLayout to layout controls

Demo Code

import java.awt.Container;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SpringLayout;

public class Main {
  public static void main(String[] args) {
    JFrame frame = new JFrame("Simplest SpringLayout");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    SpringLayout springLayout = new SpringLayout();
    contentPane.setLayout(springLayout);

    JButton b1 = new JButton("Button 1");
    JButton b2 = new JButton("this is a test 2");
    contentPane.add(b1);/*from  w ww.j  a  v a 2s.  co  m*/
    contentPane.add(b2);
    frame.pack();
    frame.setVisible(true);
  }
}

Related Tutorials