examples
Class Example1
java.lang.Object
examples.Example1
public class Example1
- extends java.lang.Object
Simplest example of using PageLayout.
Displays two panels in center of the screen. The size of the panels
is linked to the size of the container by means of calls to
the linkToContainerWidth
and linkToContainerHeight
methods.
public static void createGUI()
{
// Main Frame
JFrame frame=new JFrame();
frame.setBounds(new Rectangle(100,100,600,600));
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Container container=frame.getContentPane();
// Create Components
JPanel center=new JPanel();
center.setBorder(BorderFactory.createLineBorder(Color.black,2));
center.setBackground(new Color(200,200,255));
center.setPreferredSize(new Dimension(300,300));
JPanel bottom=new JPanel();
bottom.setBorder(BorderFactory.createLineBorder(Color.black,2));
bottom.setBackground(new Color(255,200,200));
// Top level cell. row
Column topLevel=new Column();
// First row
topLevel.newRow(Cell.CENTER,Cell.NO_ALIGNMENT,center);
// Second row
topLevel.newRow(Cell.CENTER,Cell.NO_ALIGNMENT,bottom);
// create the layout
PageLayout lm=topLevel.createLayout(container);
// Constrain component sizes to be fractions of container size.
lm.linkToContainerWidth(new Component[]{center,bottom},
new double[][]{{.9},{.60}});
lm.linkToContainerHeight(new Component[]{center,bottom},
new double[][]{{.5},{.5,-20}});
frame.show();
}
Method Summary |
static void |
createGUI()
|
static void |
main(java.lang.String[] args)
|
static void |
run()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Example1
public Example1()
createGUI
public static void createGUI()
main
public static void main(java.lang.String[] args)
run
public static void run()