Java Reference
In-Depth Information
File:
its/GridBag/GridBagFrame.java
package
its.GridBag;
1.
2.
3.
import
its.Borders.BorderPanel;
4.
import
its.SimpleFrame.SimpleFrame;
5.
import
java.awt.GridBagConstraints;
6.
import
java.awt.GridBagLayout;
7.
import
javax.swing.JComponent;
8.
9.
public class
GridBagFrame
extends
SimpleFrame
10.
{
11.
private
GridBagLayout gbl =
new
GridBagLayout();
12.
public
GridBagFrame()
13.
{
14.
this
.getContentPane().setLayout(gbl);
15.
BorderPanel panelA =
new
BorderPanel("Panel A");
16.
BorderPanel panelB =
new
BorderPanel("Panel B");
17.
BorderPanel panelC =
new
BorderPanel("Panel C");
18.
BorderPanel panelD =
new
BorderPanel("Panel D");
BorderPanel panelE =
new
BorderPanel("Panel E");
19.
BorderPanel panelF =
new
BorderPanel("Panel F");
20.
21.
22.
this
.getContentPane().add(panelA);
this
.getContentPane().add(panelB);
23.
this
.getContentPane().add(panelC);
24.
this
.getContentPane().add(panelD);
25.
this
.getContentPane().add(panelE);
26.
27.
this
.getContentPane().add(panelF);
28.
29.
easyConstraints(gbl,panelA,1,2,0,0,2.0,1.0);
30.
easyConstraints(gbl,panelB,2,1,1,0,1.0,2.0);
31.
easyConstraints(gbl,panelC,1,1,0,2,1.0,1.0);
32.
easyConstraints(gbl,panelD,1,2,1,1,1.0,1.0);
33.
easyConstraints(gbl,panelE,1,1,2,1,1.0,1.0);
34.
easyConstraints(gbl,panelF,1,1,2,2,1.0,1.0);
35.
}
36.
37.
private void
easyConstraints(GridBagLayout GLB,JComponent Comp,
38.
int
w,
int
h,
int
x,
int
y,
double
wx,
double
wy){
39.
GridBagConstraints constraints =
new
GridBagConstraints();
40.
constraints.fill = GridBagConstraints.BOTH;
constraints.gridwidth = w;
41.
constraints.gridheight = h;
42.
constraints.gridx = x;
43.
constraints.gridy = y;
44.
Search WWH ::
Custom Search