Module 2

421 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
421
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Module 2

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

×