Java Reference
In-Depth Information
SpringLayout layout = new SpringLayout ();
setLayout (layout);
JButton one = new JButton ("One");
JButton two = new JButton ("Two");
JButton three = new JButton ("Three");
JButton four = new JButton ("Four");
JButton five = new JButton ("Five");
add (one);
add (two);
add (three);
add (four);
add (five);
// Now set the distances between the edges
// Put the first button at pixel coords (5,5)
// relative to the panel's frame.
layout.putConstraint (SpringLayout.WEST, one,
5, SpringLayout.WEST, this);
layout.putConstraint (SpringLayout.NORTH, one,
5, SpringLayout.NORTH, this);
// Put the second button 5 pixels to the right of the
// first button and 40 pixels below the top panel edge
layout.putConstraint (SpringLayout.WEST, two,
5, SpringLayout.EAST, one);
layout.putConstraint (SpringLayout.NORTH, two,
40,SpringLayout.NORTH, this);
// Put the third button 100 pixels to the left of the
// panel edge and 5 pixels above the second button
layout.putConstraint (SpringLayout.WEST, three,
100, SpringLayout.WEST, this);
layout.putConstraint (SpringLayout.NORTH, three,
5, SpringLayout.SOUTH, two);
// Put the fourth button 15 pixels to the right of the
// first button and 5 pixels below the top panel edge
layout.putConstraint (SpringLayout.WEST, four,
15, SpringLayout.EAST, one);
layout.putConstraint (SpringLayout.NORTH, four,
5, SpringLayout.NORTH, this);
// Put the fifth button 25 pixels to the right of the
 
Search WWH ::




Custom Search