SlideShare a Scribd company logo
1 of 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.

More Related Content

Similar to Layout managementand event handling

8layout Managers
8layout Managers8layout Managers
8layout ManagersAdil 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.docxolsenlinnea427
 
Graphical User Interface in JAVA
Graphical User Interface in JAVAGraphical User Interface in JAVA
Graphical User Interface in JAVAsuraj pandey
 
java-layoutmanager-151027135512-lva1-app6892.pdf
java-layoutmanager-151027135512-lva1-app6892.pdfjava-layoutmanager-151027135512-lva1-app6892.pdf
java-layoutmanager-151027135512-lva1-app6892.pdfssuserec53e73
 
Java layoutmanager
Java layoutmanagerJava layoutmanager
Java layoutmanagerArati Gadgil
 
Java GUI PART II
Java GUI PART IIJava GUI PART II
Java GUI PART IIOXUS 20
 
Understanding layout managers
Understanding layout managersUnderstanding layout managers
Understanding layout managersNuha Noor
 
[C++ GUI Programming with Qt4] chap6
[C++ GUI Programming with Qt4] chap6[C++ GUI Programming with Qt4] chap6
[C++ GUI Programming with Qt4] chap6Picker Weng
 
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)Windham Document Systems
 
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsbabhishekmathuroffici
 
Advanced Java programming
Advanced Java programmingAdvanced Java programming
Advanced Java programmingvanmathy1
 

Similar to 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
 

Recently uploaded

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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...Miguel Araújo
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
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...Drew Madelung
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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...Enterprise Knowledge
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Recently uploaded (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
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...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

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.