Core Java

Debasish Pratihari

LayoutManager :


LayoutManager determines the way components
will be arranged inside the container.



All container’s have their default LayoutManger.



However You can apply a different
LayoutManager to the containers if required.



LayoutManager Classes are Provided in
java.awt and javax.swing package.

FlowLayoutManager :


FlowLayout Manager lays down the components
in a row and automatically spills components
onto the next row if row is full.



The default positing of the components is
centered in the container, and the default
orientation is from left to right.



Constants to Control FlowLayoutManager:
o LEFT
o RIGHT
o CENTER
o LEADING
TRAILING



Examples:


FlowLayout f= new FlowLayout();



FlowLayout f= new
FlowLayout(FlowLayout.LEFT);



FlowLayout f= new
FlowLayout(FlowLayout.LEFT,10,20);

Lecture/core/awt4/16

Page #1

feel the Technology…
Core Java

Debasish Pratihari

BorderLayoutManager:


The BorderLayoutManager divides the container
into file regions like
o EAST
o WEST
o NORTH
o SOUTH
o CENTER.



Each region can accommodate only one
component.

Example :
import java.awt.*;
class BorderTest extends Frame{
Button b1,b2,b3,b4,b5;
BorderTest(){
b1= new Button("EAST");
b2= new Button("WEST");
b3= new Button("NORTH");
b4= new Button("SOUTH");
b5=new Button("CENTER");
add(b1, BorderLayout.EAST);
add(b2,BorderLayout.WEST);
add(b3,BorderLayout.NORTH);
add(b4,BorderLayout.SOUTH);
add(b5,BorderLayout.CENTER);
setTitle("BorderDemo By Debasish Pratihari");
setSize(200,200);
setVisible(true);
}
public static void main(String args[]){
new BorderTest();
}
}

Lecture/core/awt4/16

Page #2

feel the Technology…
Core Java

Debasish Pratihari

CardLayout:


The CardLayout manager arrange the
components in a stack, one on the top of
another.



The first component will be at the top, so will be
the only visible component.



Methods to operate CardLayout
o void previous(Container parent)
o void first (Container parent)
o void last(Container parent)
o void show(Container parent)

Example :
import java.awt.*;
import java.awt.event.*;
class CardTest extends Frame implements ActionListener{
Button b1,b2,b3,b4,b5;
CardLayout card;
CardTest(){
b1= new Button("JAVA");
b2= new Button("J2EE");
b3= new Button("C");
b4= new Button("C++");
b5=new Button("ORACLE");
card= new CardLayout(20,50);
setLayout(card);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
add(b1,"card
add(b2,"card
add(b3,"card
add(b4,"card
add(b5,"card

1");
2");
3");
4");
5");

setTitle("BorderDemo By Debasish Pratihari");
setSize(200,200);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
card.next(this);
}
}
public static void main(String args[]){
new CardTest();
}
}
Lecture/core/awt4/16

Page #3

feel the Technology…
Core Java

Debasish Pratihari

GridLayout:
 A GridLayout manager arranges components in
a rectangular grid within a container.
Constructors:


GridLayout()



GridLayout(int rows, int cols)



GridLayout(int
vgaps)

rows,int

cols,

int

hgaps,

int

Example :
import java.awt.*;
25%

Note :

class GridTest extends Frame {
GridTest(){
GridLayout layout= new GridLayout(3,3,10,10);
setLayout(layout);
for(int i=1;i<=9;i++)
add(new Button("Button "+i));

If you want the window
to assume the size that
just accommodates the
component it contains,
use pack()

setTitle("GridDemo By Debasish Pratihari");
setVisible(true);
pack();
}
public static void main(String ar[]){
new GridTest();
}
}

Output :

Lecture/core/awt4/16

Page #4

feel the Technology…

More Related Content

PPTX
Relational Database Management System
DOC
Ficha de Dados Pessoais 2010 6º ano
PPT
Fip lezing Istanbul deel 2
PDF
Hva Lezing
PDF
PyCon 2011 Scaling Disqus
ODT
Guia de blogger
PPTX
设计资料总结
KEY
Lecture somerset webversie
Relational Database Management System
Ficha de Dados Pessoais 2010 6º ano
Fip lezing Istanbul deel 2
Hva Lezing
PyCon 2011 Scaling Disqus
Guia de blogger
设计资料总结
Lecture somerset webversie

Viewers also liked (20)

PDF
Lecture 18
PDF
Javaday 2009 php e java
PDF
Confsl 2010 Facebook Framework
PDF
090613 Ideo
PPT
Bolji svet - Uvodni webinar
PDF
I premios bermejos diplomas
PPT
Routines
PPT
Divosa v1.3
PPTX
The Mighty Gabby Embodying Resistance in the Creative Process
PPTX
技术培训
PPT
Kim Brown, Joint Head of Learning Development & Diversity at London Boroughs ...
PPT
Jane's walk 2012 evolution of ottawa
PPT
Rob Whiteman - Learning Pool Conference
PPT
Colin Paton
PDF
Design Challenge | Pelephone Corporate Website
KEY
Aag presentatie 3 februari
KEY
Pondres Social Marketing Event preso's
PPTX
Jammy Create presentation
PDF
Lezing TNT
PDF
The Public Sector Learning Community
Lecture 18
Javaday 2009 php e java
Confsl 2010 Facebook Framework
090613 Ideo
Bolji svet - Uvodni webinar
I premios bermejos diplomas
Routines
Divosa v1.3
The Mighty Gabby Embodying Resistance in the Creative Process
技术培训
Kim Brown, Joint Head of Learning Development & Diversity at London Boroughs ...
Jane's walk 2012 evolution of ottawa
Rob Whiteman - Learning Pool Conference
Colin Paton
Design Challenge | Pelephone Corporate Website
Aag presentatie 3 februari
Pondres Social Marketing Event preso's
Jammy Create presentation
Lezing TNT
The Public Sector Learning Community
Ad

Similar to Lecture 16 (20)

PPT
Layout managementand event handling
PPTX
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
PPT
Understanding layout managers
PPT
Java layoutmanager
PPTX
LAYOUT.pptx
DOCX
Java gives us layout managers whose responsibility it is to determine.docx
PPTX
Java card and flow layout
PPT
Graphical User Interface in JAVA
PPT
24-BuildingGUIs Complete Materials in Java.ppt
PPT
java swing
PPTX
OOP Lecture 10-JTable,JTabbedPane,LayoutManagers.pptx
PPTX
PDF
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
PPTX
AWT.pptx
PPTX
HASHIR_PPT about java coding which is frontend section.pptx
PPTX
Chapter 11.3
PPT
Chap1 1 4
PPTX
Abstract Window Toolkit_Event Handling_python
PPT
Chap1 1.4
Layout managementand event handling
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
Understanding layout managers
Java layoutmanager
LAYOUT.pptx
Java gives us layout managers whose responsibility it is to determine.docx
Java card and flow layout
Graphical User Interface in JAVA
24-BuildingGUIs Complete Materials in Java.ppt
java swing
OOP Lecture 10-JTable,JTabbedPane,LayoutManagers.pptx
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
AWT.pptx
HASHIR_PPT about java coding which is frontend section.pptx
Chapter 11.3
Chap1 1 4
Abstract Window Toolkit_Event Handling_python
Chap1 1.4
Ad

More from Debasish Pratihari (19)

PDF
Lecture 24
PDF
Lecture 23
PDF
Lecture 22
PDF
Lecture 21
PDF
Lecture 20
PDF
Lecture 19
PDF
Lecture 17
PDF
Lecture 14
PDF
Lecture 10
PDF
PDF
PDF
PDF
PDF
PDF
PDF
PDF
PDF
PDF

Recently uploaded (20)

PPTX
Custom Battery Pack Design Considerations for Performance and Safety
PDF
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
PDF
Five Habits of High-Impact Board Members
PDF
Comparative analysis of machine learning models for fake news detection in so...
PDF
The influence of sentiment analysis in enhancing early warning system model f...
PDF
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
PDF
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
PDF
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
PDF
UiPath Agentic Automation session 1: RPA to Agents
PDF
CloudStack 4.21: First Look Webinar slides
PDF
Credit Without Borders: AI and Financial Inclusion in Bangladesh
PDF
Consumable AI The What, Why & How for Small Teams.pdf
PPTX
Build Your First AI Agent with UiPath.pptx
PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
Early detection and classification of bone marrow changes in lumbar vertebrae...
PPTX
Training Program for knowledge in solar cell and solar industry
Custom Battery Pack Design Considerations for Performance and Safety
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
Five Habits of High-Impact Board Members
Comparative analysis of machine learning models for fake news detection in so...
The influence of sentiment analysis in enhancing early warning system model f...
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
UiPath Agentic Automation session 1: RPA to Agents
CloudStack 4.21: First Look Webinar slides
Credit Without Borders: AI and Financial Inclusion in Bangladesh
Consumable AI The What, Why & How for Small Teams.pdf
Build Your First AI Agent with UiPath.pptx
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
Taming the Chaos: How to Turn Unstructured Data into Decisions
Early detection and classification of bone marrow changes in lumbar vertebrae...
Training Program for knowledge in solar cell and solar industry

Lecture 16

  • 1. Core Java Debasish Pratihari LayoutManager :  LayoutManager determines the way components will be arranged inside the container.  All container’s have their default LayoutManger.  However You can apply a different LayoutManager to the containers if required.  LayoutManager Classes are Provided in java.awt and javax.swing package. FlowLayoutManager :  FlowLayout Manager lays down the components in a row and automatically spills components onto the next row if row is full.  The default positing of the components is centered in the container, and the default orientation is from left to right.  Constants to Control FlowLayoutManager: o LEFT o RIGHT o CENTER o LEADING TRAILING  Examples:  FlowLayout f= new FlowLayout();  FlowLayout f= new FlowLayout(FlowLayout.LEFT);  FlowLayout f= new FlowLayout(FlowLayout.LEFT,10,20); Lecture/core/awt4/16 Page #1 feel the Technology…
  • 2. Core Java Debasish Pratihari BorderLayoutManager:  The BorderLayoutManager divides the container into file regions like o EAST o WEST o NORTH o SOUTH o CENTER.  Each region can accommodate only one component. Example : import java.awt.*; class BorderTest extends Frame{ Button b1,b2,b3,b4,b5; BorderTest(){ b1= new Button("EAST"); b2= new Button("WEST"); b3= new Button("NORTH"); b4= new Button("SOUTH"); b5=new Button("CENTER"); add(b1, BorderLayout.EAST); add(b2,BorderLayout.WEST); add(b3,BorderLayout.NORTH); add(b4,BorderLayout.SOUTH); add(b5,BorderLayout.CENTER); setTitle("BorderDemo By Debasish Pratihari"); setSize(200,200); setVisible(true); } public static void main(String args[]){ new BorderTest(); } } Lecture/core/awt4/16 Page #2 feel the Technology…
  • 3. Core Java Debasish Pratihari CardLayout:  The CardLayout manager arrange the components in a stack, one on the top of another.  The first component will be at the top, so will be the only visible component.  Methods to operate CardLayout o void previous(Container parent) o void first (Container parent) o void last(Container parent) o void show(Container parent) Example : import java.awt.*; import java.awt.event.*; class CardTest extends Frame implements ActionListener{ Button b1,b2,b3,b4,b5; CardLayout card; CardTest(){ b1= new Button("JAVA"); b2= new Button("J2EE"); b3= new Button("C"); b4= new Button("C++"); b5=new Button("ORACLE"); card= new CardLayout(20,50); setLayout(card); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); b4.addActionListener(this); b5.addActionListener(this); add(b1,"card add(b2,"card add(b3,"card add(b4,"card add(b5,"card 1"); 2"); 3"); 4"); 5"); setTitle("BorderDemo By Debasish Pratihari"); setSize(200,200); setVisible(true); } public void actionPerformed(ActionEvent e){ card.next(this); } } public static void main(String args[]){ new CardTest(); } } Lecture/core/awt4/16 Page #3 feel the Technology…
  • 4. Core Java Debasish Pratihari GridLayout:  A GridLayout manager arranges components in a rectangular grid within a container. Constructors:  GridLayout()  GridLayout(int rows, int cols)  GridLayout(int vgaps) rows,int cols, int hgaps, int Example : import java.awt.*; 25% Note : class GridTest extends Frame { GridTest(){ GridLayout layout= new GridLayout(3,3,10,10); setLayout(layout); for(int i=1;i<=9;i++) add(new Button("Button "+i)); If you want the window to assume the size that just accommodates the component it contains, use pack() setTitle("GridDemo By Debasish Pratihari"); setVisible(true); pack(); } public static void main(String ar[]){ new GridTest(); } } Output : Lecture/core/awt4/16 Page #4 feel the Technology…