SlideShare ist ein Scribd-Unternehmen logo
1 von 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.

Weitere ähnliche Inhalte

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 

Kürzlich hochgeladen (20)

Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 

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.