examples
Class Example4
java.lang.Object
examples.Example4
public class Example4
- extends java.lang.Object
This example illustrates the use of
CellGrid
to arrange the
cells in a rectangular grid. The use of CellGrid
is
indicated here
because the two columns around the white panel and the row
below it are all required to align with it. Without the two side
columns, it would be sufficient to create a single column containing
the main white panel and the bottom row of buttons. Likewise, without
the bottom row of buttons, it would be sufficient to create a
single row of the three columns on the top.
Note that the code requires that the static methods of the class EasyCell
be imported using the import static pagelayout.EasyCell.*
statement.
public static void createGUI()
{
JFrame frame=new JFrame();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Container container=frame.getContentPane();
// Top Left column
JLabel j1=new JLabel("java1");
JLabel j2=new JLabel("java2");
JLabel j3=new JLabel("java3");
JTextField j4=new JTextField();
// Top middle column
JPanel midpanel=new JPanel();
midpanel.setBackground(Color.white);
midpanel.setBorder(
BorderFactory.createLineBorder(Color.blue,2));
// Bottom middle column
JButton b1=new JButton("Button1");
JButton b2=new JButton("Button2");
JButton b3=new JButton("Button3");
JButton b4=new JButton("Button4");
JButton b5=new JButton("Button5");
JButton b6=new JButton("Button6");
JButton b7=new JButton("Button7");
// Top right Column
JPanel c1=new JPanel();c1.setBackground(Color.blue);
JPanel c2=new JPanel();c2.setBackground(Color.red);
JPanel c3=new JPanel();c3.setBackground(Color.green);
JPanel c4=new JPanel();c4.setBackground(Color.white);
c4.setBorder(
BorderFactory.createLineBorder(Color.black,1));
JPanel d1=new JPanel();d1.setBackground(Color.green);
JPanel d2=new JPanel();d2.setBackground(Color.white);
JPanel d3=new JPanel();d3.setBackground(Color.yellow);
JPanel d4=new JPanel();d4.setBackground(Color.cyan);
d2.setBorder(
BorderFactory.createLineBorder(Color.black,1));
// Create the grid
CellGrid eg=grid(
column(right,center,j1,j2,j3,j4),
midpanel,
column(none,justified,
row(column(c1,c2),column(c3,c4)),
row(column(d1,d2),column(d3,d4))),
eol(),
skip(),
row(justified,none,
row(column(b1,b2),column(b6,b7)),
row(b3,b4,b5)),
skip());
eg.linkWidth(b1,1,b2,b6,b7,c1,c2,c3,c4,d1,d2,d3,d4);
eg.linkHeight(b1,1,b2,b6,b7,c1,c2,c3,c4,d1,d2,d3,d4);
eg.linkWidth(j3,2,j4);
eg.setFixedWidth(true,j4);
// Create the layout
eg.createLayout(container);
// pack and show
frame.pack();
frame.setSize(frame.getPreferredSize());
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 |
Example4
public Example4()
createGUI
public static void createGUI()
main
public static void main(java.lang.String[] args)
run
public static void run()