Web host - 782 Graphical User Interface Components: Part 2 Chapter

782 Graphical User Interface Components: Part 2 Chapter 13 77 78 // list –weightx and weighty are 1: fill is BOTH 79 constraints.gridwidth = GridBagConstraints.REMAINDER; 80 addComponent( list ); 81 82 setSize( 300, 200 ); 83 setVisible( true ); 84 85 } // end constructor 86 87 // addComponent is programmer-defined 88 private void addComponent( Component component ) 89 { 90 layout.setConstraints( component, constraints ); 91 container.add( component ); // add component 92 } 93 94 // execute application 95 public static void main( String args[] ) 96 { 97 GridBagDemo2 application = new GridBagDemo2(); 98 99 application.setDefaultCloseOperation( 100 JFrame.EXIT_ON_CLOSE ); 101 } 102 103 } // end class GridBagDemo2 Fig. 13.21 Demonstrating the GridBagConstraintsconstants RELATIVEand REMAINDER(part 3 of 3). Lines 22 23 construct a GridBagLayoutand set the content pane s layout manager to GridBagLayout. The components that are placed in GridBagLayoutare each constructed (lines 29 42). The components are five JButtons, one JTextField, one JListand one JComboBox. The JTextFieldis added first (lines 46 50). The weightxand weightyvalues are set to 1. The fillvariable is set to BOTH. Line 49 specifies that the JTextFieldis the last component on the line. The JTextFieldis added to the content pane with a call to our utility method addComponent(defined at lines 88 92). Method addComponent takes a Componentargument and uses GridBagLayoutmethod setConstraints to set the constraints for the Component. Method addattaches the component to the content pane.
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

Leave a Reply