Java Reference
In-Depth Information
// rows, second takes up two columns
// The first component on second row will span
// vertically to third row
// 0,1 to 0,2
constraints.weightx = 1.0;
constraints.gridx = 0; constraints.gridy = 1;
constraints.gridheight = 2;
add (new JButton ( " 0,1 to 0,2 " ), constraints);
// The second component on second row will span
// horizontally to third column
// 1,1 to 2,1
constraints.weightx = 1.0;
constraints.gridx = 1; constraints.gridy = 1;
constraints.gridheight = 1;
constraints.gridwidth = 2;
add (new JButton ( " 1,1 to 2,1 " ), constraints);
// Bottom row has 2 components with fill set to NONE
// Use anchor.
constraints.fill = GridBagConstraints.NONE;
// 1,2
constraints.anchor = GridBagConstraints.SOUTHEAST;
constraints.weightx = 0.5;
constraints.gridx = 1; constraints.gridy = 2;
constraints.gridheight = 1;
constraints.gridwidth = 1;
add (new JButton ( " 1,2 " ), constraints);
// 2,2
constraints.anchor = GridBagConstraints.WEST;
constraints.weightx = 0.1;
constraints.gridx = 2; constraints.gridy = 2;
constraints.gridheight = 1;
constraints.gridwidth = 1;
add (new JButton ( " 2,2 " ), constraints);
} // ctor
} // class GridBagPanel
7.5 Convenience classes
With Java 1.1 came several types of classes that facilitate the writing of Java
code. Some programmers feel that these convenience classes violate the spirit of
 
Search WWH ::




Custom Search