Layout Manager
A layout manager allows the java programmer to develop graphical
interfaces that will have a common appearance across the
heterogeneous internet.There are five layout managers that the
programmer may choose from:
•Flow Layout
•Grid Layout
•Border Layout
•Card Layout
•Gridbag Layout
Layout
Manager
• A Component can be displayed on a screen and a user can
interact with a Component.
• A Container is a Component that can hold other
Components.
• A Layout Manager directs the placement of Components
within a Container.
Layout
Manager
Card Layout:
• A card layout is a group of components or containers that are
displayed one at a time.
• Components or containers are placed on a card using the
statement:add (String, component);
Layout
Manager
Card Layout Construction:
• The Applet contains an ordered listing (array) of cards in one
of its panels
Layout
Manager
Applet Declarations:
• public class CardDemo extends Applet {
private final int numCards = _; //whatever the number
private String[] = new CardLabels[numCards];
//construct an array for holding CardPanel objects - specified in separate file
private CardPanel[ ] cards = new CardPanel [numCards];
private CardLayout theLayout; //Layout for CardPanels
//Create a Panel for displaying CardPanel objects in the Applet (green area)
private Panel cardDisplay Panel;
Layout
Manager
Applet initialization :
• public void init() {
//essential statements for card display
setLayout (new BorderLayout); //layout for the Applet
add("West", makeOther Panel()); //2nd parameter returns a Panel
add("Center", makeCardDisplay Panel()); /*2nd param returns a
Panel */
}
Layout
Manager
CardPanel Object:
• Card Panel is a separately declared class that extends Panel
• CardPanels are containers with their own Components and
Layout
• CardPanel objects are created in method makeCardDisplay
Panel() of Applet
• CardPanel objects are stored in the array cards
Layout
Manager
Gridbag Layout:
• GridBagLayout is the most complex and most flexible of the
layout managers.
• With GridLayout, elements are arranged in a rectangular
grid, and each element in the container is sized identically
(where possible).
• With GridBagLayout, elements can have different sizes and
can occupy multiple rows or columns
• Note: The maximum capacity of a screen using GridBagLayout is 512 rows by 512 columns. This is
specified by the protected MAXGRIDSIZE constant of the layout manager
Layout
Manager
Gridbag Layout:
• How GridBagLayout counts Rows and columns
Layout
Manager
GridBagConstraints Class :
• The magic of the layout manager is strictly controlled by the
different GridBagConstraints objects passed in for each
component added to the container.
• Each specifies how to display a specific component. Unlike
most other layout managers, which have a built-in idea
about what to do with their display, the GridBagLayout is a
blank slate.
• The constraints attached to the components tell the layout
manager how to build its display.
Thank you
• SUBMITTED BY : M.ABHIGNYA
• Roll No. : 22261A0529
• Class : CSE 1