SlideShare una empresa de 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.

Más contenido relacionado

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

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
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
 
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
 
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
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
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
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
[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
 
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
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 

Último (20)

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
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...
 
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
 
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
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
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
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
[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
 
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
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 

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.