Chapter 12 Graphical User Interface Components: Part 1 (Web hosting support)

Chapter 12 Graphical User Interface Components: Part 1 695 79 // process rightButton event 80 public void actionPerformed( ActionEvent event ) 81 { 82 layout.setAlignment( FlowLayout.RIGHT ); 83 84 // re-align attached components 85 layout.layoutContainer( container ); 86 } 87 } 88 ); 89 90 container.add( rightButton ); 91 92 setSize( 300, 75 ); 93 setVisible( true ); 94 } 95 96 // execute application 97 public static void main( String args[] ) 98 { 99 FlowLayoutDemo application = new FlowLayoutDemo(); 100 101 application.setDefaultCloseOperation( 102 JFrame.EXIT_ON_CLOSE ); 103 } 104 105 } // end class FlowLayoutDemo Fig. 12.24 Program that demonstrates components in FlowLayout(part 3 of 3). As seen previously, a container s layout is set with method setLayout of class Container. Line 25 sets the content pane s layout manager to the FlowLayoutdefined at line 21. Normally, the layout is set before any GUI components are added to a container. Look-and-Feel Observation 12.10 Each container can have only one layout manager at a time. (Separate containers in the same program can have different layout managers.) Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01

Leave a Reply