Apr 17, 2012

Layout Managers


The arrangement of several components within a container is called their layout. java components borrow their behaviour from the window. The Button, TextBox and other components have different size when instantiated on different platforms. Suppose you have to create a button on your application. The application runs on windows 95 machine, this button will be 32 pixels wide and 21 pixels height. Pixel(picture element) is a small graphical unit. On a Motif platform button will be 32 pixels wide and 22 pixels height, even though it uses the same font. Java solve the problem by using the Layout manager.

Java defines the five layout classes FlowLayout, GridLayout, BorderLayout, CardLayout and GridBagLayout. These are all subclass of the java.awt.LayoutManager class. You can set the layout by using the setLayout() method.

Notes 1: A panel’s default layout manager is always FlowLayout
          2: An applet’s default layout manager is always FlowLayout and constraint is
                FlowLayout.CENTER
          3: A frame’s default layout manager is always BorderLayout.



0 comments :

Post a Comment