package springlayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SpringLayout;
public class SpringLayoutTest extends JPanel{
public SpringLayoutTest() {
SpringLayout mySpringLayout = new SpringLayout();
JPanel myPanel = new JPanel(mySpringLayout);
JButton helloButton = new JButton("hello");
myPanel.add(helloButton);
mySpringLayout.putConstraint(SpringLayout.WEST, helloButton, 10, SpringLayout.WEST, myPanel);
mySpringLayout.putConstraint(SpringLayout.NORTH, helloButton, 10, SpringLayout.NORTH, myPanel);
this.add(myPanel);
}
/**
*
* @param s
*/
public static void main(String s[]) {
JFrame frame = new JFrame("SpringLayoutTest");
SpringLayoutTest springLayoutTest = new SpringLayoutTest();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(springLayoutTest);
frame.setSize(300, 300);
frame.setLocation(300,300);
frame.setVisible(true);
}
} |