696 Graphical User Interface Components: Part 1 Chapter (Php web hosting)

696 Graphical User Interface Components: Part 1 Chapter 12 Each button s actionPerformed event handler executes two statements. For example, line 38 in method actionPerformed for button left uses FlowLayout method setAlignmentto change the alignment for the FlowLayoutto a left-aligned (FlowLayout.LEFT) FlowLayout. Line 41 uses LayoutManager interface method layoutContainerto specify that the content pane should be rearranged based on the adjusted layout. According to which button was clicked, the actionPerformed method for each button sets the FlowLayout s alignment to FlowLayout.LEFT, Flow- Layout.CENTERor FlowLayout.RIGHT. 12.14.2 BorderLayout The BorderLayoutlayout manager (the default layout manager for the content pane) arranges components into five regions: NORTH, SOUTH, EAST, WESTand CENTER(North corresponds to the top of the container). Class BorderLayout inherits from Object and implements interface LayoutManager2 (a subinterface of LayoutManager that adds several methods for enhanced layout processing). Up to five components can be added directly to a BorderLayout one for each region. The component placed in each region can be a container to which other components are attached. The components placed in the NORTHand SOUTHregions extend horizontally to the sides of the container and are as tall as the components placed in those regions. The EASTand WESTregions expand vertically between the NORTHand SOUTHregions and are as wide as the components placed in those regions. The component placed in the CENTER region expands to take all remaining space in the layout (this is the reason the JTextArea in Fig. 12.22 occupies the entire window). If all five regions are occupied, the entire container s space is covered by GUI components. If the NORTHor SOUTHregion is not occupied, the GUI components in the EAST, CENTER and WEST regions expand vertically to fill the remaining space. If the EASTor WEST region is not occupied, the GUI component in the CENTER region expands horizontally to fill the remaining space. If the CENTER region is not occupied, the area is left empty the other GUI components do not expand to fill the remaining space. The application of Fig. 12.25 demonstrates the BorderLayout layout manager by using five JButtons. 1 // Fig. 12.25: BorderLayoutDemo.java 2 // Demonstrating BorderLayout. 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 BorderLayoutDemo extends JFrame 12 implements ActionListener { 13 Fig. 12.25 Demonstrating components in BorderLayout(part 1 of 3). Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01

Leave a Reply