780 Graphical User Interface Components: Part 2 Chapter (Web site counters)
780 Graphical User Interface Components: Part 2 Chapter 13 grow if the window is resized; it is affected by the weight values of button2. Note that the weightx value for button2 is much larger than button3. When resizing occurs, button2will occupy a larger percentage of the new space. The button is placed at row 1, column 2. One row and one column are occupied. Both the JTextField (line 70) and JTextArea textArea2 (line 74) have a weightx value 0 and a weighty value 0. The value of fill is BOTH. The JText- Field is placed at row 3, column 0, and the JTextArea is placed at row 3, column 2. The JTextField occupies one row and two columns. The JTextArea occupies one row and one column. When you execute this application, try resizing the window to see how the constraints for each GUI component affect its position and size in the window. 13.16 GridBagConstraintsConstants RELATIVEand REMAINDER A variation of GridBagLayout does not use gridx and gridy. Rather, Gridbag- Constraints constants RELATIVE and REMAINDER are used in their place. RELATIVE specifies that the next-to-last component in a particular row should be placed to the right of the previous component in that row. REMAINDERspecifies that a component is the last component in a row. Any component that is not the second-to-last or last component on a row must specify values for GridbagConstraints variables gridwidth and gridheight. Class GridBagDemo2in Fig. 13.21 arranges components in GridBag- Layout, using these constants. 1 // Fig. 13.21: GridBagDemo2.java 2 // Demonstrating GridBagLayout constants. 3 4 // Java core packages 5 import java.awt.*; 6 import java.awt.event.*; 7 8 // Java extension packages 9 import javax.swing.*; 10 11 public class GridBagDemo2 extends JFrame { 12 private GridBagLayout layout; 13 private GridBagConstraints constraints; 14 private Container container; 15 16 // set up GUI 17 public GridBagDemo2() 18 { 19 super( “GridBagLayout” ); 20 21 container = getContentPane(); 22 layout = new GridBagLayout(); 23 container.setLayout( layout ); 24 Fig. 13.21 Demonstrating the GridBagConstraintsconstants RELATIVEand REMAINDER(part 1 of 3).
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.