SlideShare uma empresa Scribd logo
1 de 13
Ch 20
Layout Management and Event
Handling
Layout Managers
 Removes repetitious need to lay out
components precisely.
 Insulates developer from the fact that
components have different sizes when
instantiated on different platforms.
 All implement java.awt.LayoutManager
interface.
Layout of Components
 FlowLayout
 left to right & top
down
 BorderLayout
 north, south,
west, east &
center
 CardLayout
 stack of panels
 GridLayout
 tabular form
(rows &
columns)
 GridBagLayout
 tabular
form(variable
row heights and
column widths)
Component Size and Position
 Sizes and positions are merely suggestions,
overridden by the LayoutManager.
 Each Component has a preferred size, which
is “just big enough” to display the component.
Use Layout Managers
 Default layout managers
 Windows (Frames & Dialogs)
 BorderLayout
 Panels & Applets
 FlowLayout
setLayout(new FlowLayout());
setLayout(new BorderLayout());
setLayout(new CardLayout(());
setLayout(new
GridLayout(rows,columns,xgap,ygap));
 FlowLayout
 The flow layout is the default layout manager for all
Panel objects and applets.
 It simply lays out components in a single row, from
left to right starting a new row if its container is not
sufficiently wide .
 Default alignment is CENTER.
 new FlowLayout() // default is centered with 5 pixel
gaps
 new FlowLayout(int align)
 new FlowLayout(int align, int hgap, int vgap)
GridLayout
 GridLayout lays out components in a rectangular grid,
where all cells are equal size.
 Components are addes cell by cell left to right ,filling
top row and then moving down
 GridLayout()
default of one column per component, in a single row.
 GridLayout(int rows, int cols)
Creates a grid layout with the specified number
of rows and columns.
 GridLayout(int rows, int cols, int hgap, int vgap)
Creates a grid layout with the specified number
of rows and columns.
 e.g setLayout(new GridLayout(3,5,10,15));
BorderLayout
 Divides the container into five regions: east,
south, west, north, and center.
 Takes maximum 5 components only, one per
region.
 Resizes each component to match the size of
its region.
 Resizes each region when the container is
resized.
BorderLayout Manager
“Center”
“North”
“South”
“West” “East”
 While adding a component a region is
specified as an argument to add()
as BorderLayout.NORTH
 e.g add(new
Button(“OK”),BorderLayout.SOUTH);
GridBagLayout
 GridBagLayout is a flexible layout manager
that aligns components vertically and
horizontally, without requiring that the
components be the same size .
 GridBagLayout (int gridx , int gridy, int
gridwidth ,int gridheight ,int weightx,
double weighty double anchor, int fill ,int
insets , int ipadx int ipady )
 gridx,gridy : define col ,and row position of upper left
corner.
 gridwidth ,gridheight : no of cells occupied by
components .default is 1 for both
 weightx,weighty: Specifies how to distribute extra
horizontal space
 anchor:It determines where, within the display area,
to place the component.
 fill:This field is used when the component's display
area is larger than the component's requested size.
 Insets:This field specifies the external padding of the
component, the minimum amount of space between
the component and the edges of its display area.
 Ipadx, ipady:This field specifies the internal padding
 CardLayout:The CardLayout class lets you
implement an area that contains different
components at different times .
 CardLayout()
Creates a new card layout with gaps of
size zero .
 CardLayout(int hgap, int vgap)
Creates a new card layout with the
specified horizontal and vertical gaps.

Mais conteúdo relacionado

Semelhante a Layout managementand event handling

8layout Managers
8layout Managers8layout Managers
8layout Managers
Adil Jafri
 
Java gives us layout managers whose responsibility it is to determine.docx
Java gives us layout managers whose responsibility it is to determine.docxJava gives us layout managers whose responsibility it is to determine.docx
Java gives us layout managers whose responsibility it is to determine.docx
olsenlinnea427
 
java-layoutmanager-151027135512-lva1-app6892.pdf
java-layoutmanager-151027135512-lva1-app6892.pdfjava-layoutmanager-151027135512-lva1-app6892.pdf
java-layoutmanager-151027135512-lva1-app6892.pdf
ssuserec53e73
 

Semelhante a Layout managementand event handling (20)

Layout manager
Layout managerLayout manager
Layout manager
 
Java
JavaJava
Java
 
8layout Managers
8layout Managers8layout Managers
8layout Managers
 
Java gives us layout managers whose responsibility it is to determine.docx
Java gives us layout managers whose responsibility it is to determine.docxJava gives us layout managers whose responsibility it is to determine.docx
Java gives us layout managers whose responsibility it is to determine.docx
 
Graphical User Interface in JAVA
Graphical User Interface in JAVAGraphical User Interface in JAVA
Graphical User Interface in JAVA
 
java-layoutmanager-151027135512-lva1-app6892.pdf
java-layoutmanager-151027135512-lva1-app6892.pdfjava-layoutmanager-151027135512-lva1-app6892.pdf
java-layoutmanager-151027135512-lva1-app6892.pdf
 
Java layoutmanager
Java layoutmanagerJava layoutmanager
Java layoutmanager
 
Javalayout
JavalayoutJavalayout
Javalayout
 
swingbasics
swingbasicsswingbasics
swingbasics
 
Java GUI PART II
Java GUI PART IIJava GUI PART II
Java GUI PART II
 
LayoutManager_Lec1.pptx
LayoutManager_Lec1.pptxLayoutManager_Lec1.pptx
LayoutManager_Lec1.pptx
 
Understanding layout managers
Understanding layout managersUnderstanding layout managers
Understanding layout managers
 
[C++ GUI Programming with Qt4] chap6
[C++ GUI Programming with Qt4] chap6[C++ GUI Programming with Qt4] chap6
[C++ GUI Programming with Qt4] chap6
 
Chap1 1 4
Chap1 1 4Chap1 1 4
Chap1 1 4
 
java swing
java swingjava swing
java swing
 
Chap1 1.4
Chap1 1.4Chap1 1.4
Chap1 1.4
 
Raster to Vector Conversion: Basic Commands Overview, A Lesson from GTX (Part 2)
Raster to Vector Conversion: Basic Commands Overview, A Lesson from GTX (Part 2)Raster to Vector Conversion: Basic Commands Overview, A Lesson from GTX (Part 2)
Raster to Vector Conversion: Basic Commands Overview, A Lesson from GTX (Part 2)
 
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
 
Advanced Java programming
Advanced Java programmingAdvanced Java programming
Advanced Java programming
 
Java swing
Java swingJava swing
Java swing
 

Último

Último (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Layout managementand event handling

  • 1. Ch 20 Layout Management and Event Handling
  • 2. Layout Managers  Removes repetitious need to lay out components precisely.  Insulates developer from the fact that components have different sizes when instantiated on different platforms.  All implement java.awt.LayoutManager interface.
  • 3. Layout of Components  FlowLayout  left to right & top down  BorderLayout  north, south, west, east & center  CardLayout  stack of panels  GridLayout  tabular form (rows & columns)  GridBagLayout  tabular form(variable row heights and column widths)
  • 4. Component Size and Position  Sizes and positions are merely suggestions, overridden by the LayoutManager.  Each Component has a preferred size, which is “just big enough” to display the component.
  • 5. Use Layout Managers  Default layout managers  Windows (Frames & Dialogs)  BorderLayout  Panels & Applets  FlowLayout setLayout(new FlowLayout()); setLayout(new BorderLayout()); setLayout(new CardLayout(()); setLayout(new GridLayout(rows,columns,xgap,ygap));
  • 6.  FlowLayout  The flow layout is the default layout manager for all Panel objects and applets.  It simply lays out components in a single row, from left to right starting a new row if its container is not sufficiently wide .  Default alignment is CENTER.  new FlowLayout() // default is centered with 5 pixel gaps  new FlowLayout(int align)  new FlowLayout(int align, int hgap, int vgap)
  • 7. GridLayout  GridLayout lays out components in a rectangular grid, where all cells are equal size.  Components are addes cell by cell left to right ,filling top row and then moving down  GridLayout() default of one column per component, in a single row.  GridLayout(int rows, int cols) Creates a grid layout with the specified number of rows and columns.  GridLayout(int rows, int cols, int hgap, int vgap) Creates a grid layout with the specified number of rows and columns.  e.g setLayout(new GridLayout(3,5,10,15));
  • 8. BorderLayout  Divides the container into five regions: east, south, west, north, and center.  Takes maximum 5 components only, one per region.  Resizes each component to match the size of its region.  Resizes each region when the container is resized.
  • 10.  While adding a component a region is specified as an argument to add() as BorderLayout.NORTH  e.g add(new Button(“OK”),BorderLayout.SOUTH);
  • 11. GridBagLayout  GridBagLayout is a flexible layout manager that aligns components vertically and horizontally, without requiring that the components be the same size .  GridBagLayout (int gridx , int gridy, int gridwidth ,int gridheight ,int weightx, double weighty double anchor, int fill ,int insets , int ipadx int ipady )
  • 12.  gridx,gridy : define col ,and row position of upper left corner.  gridwidth ,gridheight : no of cells occupied by components .default is 1 for both  weightx,weighty: Specifies how to distribute extra horizontal space  anchor:It determines where, within the display area, to place the component.  fill:This field is used when the component's display area is larger than the component's requested size.  Insets:This field specifies the external padding of the component, the minimum amount of space between the component and the edges of its display area.  Ipadx, ipady:This field specifies the internal padding
  • 13.  CardLayout:The CardLayout class lets you implement an area that contains different components at different times .  CardLayout() Creates a new card layout with gaps of size zero .  CardLayout(int hgap, int vgap) Creates a new card layout with the specified horizontal and vertical gaps.