Weitere ähnliche Inhalte Ähnlich wie Module 2 (20) Kürzlich hochgeladen (20) Module 22. 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.
7. What happens when the user resize a window?
How does my component look like?
How you guys solve platform-dependent
positioning?
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))
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
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
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