SlideShare a Scribd company logo
Layout
Managers
What is a Layout Manager?
     a object associated with a container
            which governs the placement and size of the component
All containers
     whether top-level or general-purpose
           are based on a Layout Manager.
JFrame, JApplet has BorderLayout by default
Why needs Layout Manager?
Normal not Layout Manager:
    Set an absolute size for components
What happens when the user resize a window?
     How does my component look like?

How you guys solve platform-dependent
positioning?
Okay. Layout Manager takes care of this for you.
LayoutManager based on
    minimumSize, preferedSize, maximumSize
          to resize and arrange components on the screen
Steps for using Layout Managers
     1. setLayout()
       Container contentPane = frame.getContentPane();
       contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.X_AXIS));
Steps for using Layout Managers
     2. specify size
            | void setPreferredSize(Dimension preferredSize)
            | void setMinimumSize(Dimension minimumSize)
            | void setMaximumSize(Dimension maximumSize)

            | btnOk.setPreferredSize(new Dimension (20,20))
Steps for using Layout Managers
     3. pack()
     4. setVisible()
Types of Layout Manager
     FlowLayout
     BorderLayout
Types of Layout Manager
     GridLayout



     CardLayout
FlowLayout
    Constructors
          public FlowLayout()
          public FlowLayout(int alignment)
          public FlowLayout(int alignment, int hgap, int vgap)
FlowLayout
    Alignments:
          CENTER
          LEADING
          LEFT
          RIGHT
          TRAILING
FlowLayout
    Benefits
          Simple to use
          Centers layout for bigger container
          Suitable for JApplet
FlowLayout
    Drawbacks
         Resize loose alignment
         No complex alighment
BorderLayout
    by default in center
BorderLayout
    Alignment
          AFTER_LAST_LINE, PAGE_END, SOUTH
          AFTER_LINE_ENDS, LINE_END, EAST
          BEFORE_FIRST_LINE, PAGE_START, NORTH
          BEFORE_LINE_BEGINS, LINE_START, WEST
          CENTER
BorderLayout
    Constructor
          public BorderLayout()

          public BorderLayout(int hgap, int vgap)
BorderLayout
    Adv.
           Can specify direction

    Dis.
           Only five locations to add components
           No high complexity
GridLayout
     setLayout(new GridLayout(3, 4))
GridLayout
     public GridLayout()
     public GridLayout(int rows, int columns)
     public GridLayout(int rows, int columns, int hgap, int vgap)
GridLayout
     Adv.
             Simple to use
             Useful for rectangular pattern
             Same size component

     Dis.
             Cannot create a complex layout
CardLayout
CardLayout
    CardLayout()
    CardLayout(int horizontal_gap, int vertical_gap)
CardLayout
CardLayout
    void first(Container parent)
    void next(Container parent)
    void previous(Container parent)
    void last(Container parent)
CardLayout
          Adv.
                 Containers and their associated components to share the
same space in the container

          Dis.
                 Not visually appealing as a Tabbed pane
                 Requires other components like buttons or drop-down to flip
through

More Related Content

PPT
Layout managementand event handling
PDF
Version numbering system
PDF
Android drawing and graphics API
PDF
Android drawing and graphics api
PPTX
Cut mix: Regularization strategy to train strong classifiers with localizable...
DOCX
Questão de ordem - suspeição do relator da Comissão de Impeachment
PPTX
Cooll usersguide 1
PPSX
Inanimate Alice Episode 5 by Ben & George
Layout managementand event handling
Version numbering system
Android drawing and graphics API
Android drawing and graphics api
Cut mix: Regularization strategy to train strong classifiers with localizable...
Questão de ordem - suspeição do relator da Comissão de Impeachment
Cooll usersguide 1
Inanimate Alice Episode 5 by Ben & George

Viewers also liked (20)

PPT
Shifts in the music industry
PPT
Corespring
PPTX
Tensioned Membrane Structures In India
PPTX
Basic conversation 5
PDF
O3sac energia-jpb 2012
PDF
Egoera: La economía de Bizkaia - Mayo 2016 - nº22. Cámara de Comercio de Bilbao
PPTX
Developing your School's WOM Marketing Plan, TAIS 2012
PDF
Startgids Accounthouder
PDF
Big data movement webcast
PPT
Ch. 10 -_motivation and engagement
PDF
Denúncia da Lava Jato contra João Santana
PDF
Can Social Media Influence Behavior - We Walk the Talk - CS377T Final Present...
PDF
Linseele,v.s af a2006- pastoralists in africa
PPTX
Basketball game
PPTX
Paper mill – comana, romania
KEY
Smsvideoconferencing slideshare
PPTX
Creative Technosoft System - Company Profile
PPT
Research designku rev
PPTX
Morgana matariki pp presentation
Shifts in the music industry
Corespring
Tensioned Membrane Structures In India
Basic conversation 5
O3sac energia-jpb 2012
Egoera: La economía de Bizkaia - Mayo 2016 - nº22. Cámara de Comercio de Bilbao
Developing your School's WOM Marketing Plan, TAIS 2012
Startgids Accounthouder
Big data movement webcast
Ch. 10 -_motivation and engagement
Denúncia da Lava Jato contra João Santana
Can Social Media Influence Behavior - We Walk the Talk - CS377T Final Present...
Linseele,v.s af a2006- pastoralists in africa
Basketball game
Paper mill – comana, romania
Smsvideoconferencing slideshare
Creative Technosoft System - Company Profile
Research designku rev
Morgana matariki pp presentation
Ad

Similar to Module 2 (20)

PPT
24-BuildingGUIs Complete Materials in Java.ppt
PPTX
PPT
java swing
PPTX
LAYOUT.pptx
PPT
Chap1 1 4
PPT
Understanding layout managers
PPTX
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
DOCX
Java gives us layout managers whose responsibility it is to determine.docx
PPT
Chap1 1.4
PPTX
LayoutManager_Lec1.pptx
PPT
Java layoutmanager
PPTX
Advanced Java programming
PPT
Java AWR LayoutManagers for B. Tech. 2nd Year.ppt
PPTX
Abstract Window Toolkit_Event Handling_python
PDF
8layout Managers
PPT
Graphical User Interface in JAVA
PPTX
Chapter 11.3
PDF
swingbasics
PPT
GUI Programming In Java
24-BuildingGUIs Complete Materials in Java.ppt
java swing
LAYOUT.pptx
Chap1 1 4
Understanding layout managers
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
Java gives us layout managers whose responsibility it is to determine.docx
Chap1 1.4
LayoutManager_Lec1.pptx
Java layoutmanager
Advanced Java programming
Java AWR LayoutManagers for B. Tech. 2nd Year.ppt
Abstract Window Toolkit_Event Handling_python
8layout Managers
Graphical User Interface in JAVA
Chapter 11.3
swingbasics
GUI Programming In Java
Ad

More from Tuan Ngo (20)

PDF
Introduction of cg program for portal 20120424 en
PDF
Net framework
PDF
15 anonymous methods, partial types and nullable types
PDF
14 generics and iterators
PDF
13 collections
PDF
11 exception handling
PDF
12 events and delegates
PDF
9 properties & indexers
PDF
10 namespace
PDF
8 abstract classes and interfaces
PDF
7 inheritance and polymorphism
PDF
5 arrays
PDF
6 class and methods
PDF
3 statements and operators
PDF
4 c# programming constructs
PDF
1 get started with c#
PDF
2 variables and data types
PDF
Jdbc 7
PDF
Jdbc 6
PDF
Jdbc 3
Introduction of cg program for portal 20120424 en
Net framework
15 anonymous methods, partial types and nullable types
14 generics and iterators
13 collections
11 exception handling
12 events and delegates
9 properties & indexers
10 namespace
8 abstract classes and interfaces
7 inheritance and polymorphism
5 arrays
6 class and methods
3 statements and operators
4 c# programming constructs
1 get started with c#
2 variables and data types
Jdbc 7
Jdbc 6
Jdbc 3

Recently uploaded (20)

PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
KodekX | Application Modernization Development
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Big Data Technologies - Introduction.pptx
PDF
Encapsulation theory and applications.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
KodekX | Application Modernization Development
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Big Data Technologies - Introduction.pptx
Encapsulation theory and applications.pdf
Understanding_Digital_Forensics_Presentation.pptx
20250228 LYD VKU AI Blended-Learning.pptx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Encapsulation_ Review paper, used for researhc scholars
Diabetes mellitus diagnosis method based random forest with bat algorithm
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Dropbox Q2 2025 Financial Results & Investor Presentation
Review of recent advances in non-invasive hemoglobin estimation
Mobile App Security Testing_ A Comprehensive Guide.pdf
NewMind AI Monthly Chronicles - July 2025
MYSQL Presentation for SQL database connectivity
Building Integrated photovoltaic BIPV_UPV.pdf

Module 2

  • 2. What is a Layout Manager? a object associated with a container which governs the placement and size of the component
  • 3. All containers whether top-level or general-purpose are based on a Layout Manager.
  • 4. JFrame, JApplet has BorderLayout by default
  • 5. Why needs Layout Manager?
  • 6. Normal not Layout Manager: Set an absolute size for components
  • 7. What happens when the user resize a window? How does my component look like? How you guys solve platform-dependent positioning?
  • 8. Okay. Layout Manager takes care of this for you.
  • 9. LayoutManager based on minimumSize, preferedSize, maximumSize to resize and arrange components on the screen
  • 10. Steps for using Layout Managers 1. setLayout() Container contentPane = frame.getContentPane(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.X_AXIS));
  • 11. Steps for using Layout Managers 2. specify size | void setPreferredSize(Dimension preferredSize) | void setMinimumSize(Dimension minimumSize) | void setMaximumSize(Dimension maximumSize) | btnOk.setPreferredSize(new Dimension (20,20))
  • 12. Steps for using Layout Managers 3. pack() 4. setVisible()
  • 13. Types of Layout Manager FlowLayout BorderLayout
  • 14. Types of Layout Manager GridLayout CardLayout
  • 15. FlowLayout Constructors public FlowLayout() public FlowLayout(int alignment) public FlowLayout(int alignment, int hgap, int vgap)
  • 16. FlowLayout Alignments: CENTER LEADING LEFT RIGHT TRAILING
  • 17. FlowLayout Benefits Simple to use Centers layout for bigger container Suitable for JApplet
  • 18. FlowLayout Drawbacks Resize loose alignment No complex alighment
  • 19. BorderLayout by default in center
  • 20. BorderLayout Alignment AFTER_LAST_LINE, PAGE_END, SOUTH AFTER_LINE_ENDS, LINE_END, EAST BEFORE_FIRST_LINE, PAGE_START, NORTH BEFORE_LINE_BEGINS, LINE_START, WEST CENTER
  • 21. BorderLayout Constructor public BorderLayout() public BorderLayout(int hgap, int vgap)
  • 22. BorderLayout Adv. Can specify direction Dis. Only five locations to add components No high complexity
  • 23. GridLayout setLayout(new GridLayout(3, 4))
  • 24. GridLayout public GridLayout() public GridLayout(int rows, int columns) public GridLayout(int rows, int columns, int hgap, int vgap)
  • 25. GridLayout Adv. Simple to use Useful for rectangular pattern Same size component Dis. Cannot create a complex layout
  • 27. CardLayout CardLayout() CardLayout(int horizontal_gap, int vertical_gap)
  • 29. CardLayout void first(Container parent) void next(Container parent) void previous(Container parent) void last(Container parent)
  • 30. CardLayout Adv. Containers and their associated components to share the same space in the container Dis. Not visually appealing as a Tabbed pane Requires other components like buttons or drop-down to flip through