Trusted by millions of Kenyans
Study resources on Kenyaplex

Get ready-made curriculum aligned revision materials

Exam papers, notes, holiday assignments and topical questions – all aligned to the Kenyan curriculum.

Differentiate between the following layout managers i. GridLayout ii. BorderLayout iii. FlowLayout

Differentiate between the following layout managers
i. GridLayout
ii. BorderLayout
iii. FlowLayout

Answers


gregory
i. GridLayout
Arranges components into rows and columns
In Frame’s constructor:
setLayout(new GridLayout(rows,columns))
OR
setLayout(new GridLayout(rows,columns,hgap,vgap))
Components will be added in order, left to right, row by row
Components will be equal in size
As container is resized, components will resize accordingly, and remain in same grid arrangement
ii. BorderLayout
Arranges components into five areas: North, South, East, West, and Center
In the constructor:
setLayout(new BorderLayout())
OR
setLayout(new BorderLayout(hgap,vgap))
for each component:
add (the_component, region)
do for each area desired:
BorderLayout.EAST, BorderLayout.SOUTH, BorderLayout.WEST, BorderLayout.NORTH, or
BorderLayout.CENTER
Behavior: when the container is resized, the components will be resized but remain in the same locations.
NOTE: only a maximum of five components can be added and seen in this case, one to each region.
iii. FlowLayout
Places components sequentially (left-to-right) in the order they were added
Components will wrap around if the width of the container is not wide enough to hold them all in a row.
Default for applets and panels, but not for frames
Options: left, center (this is the default), or right Typical syntax: in your Frame class’s constructor
setLayout(new FlowLayout(FlowLayout.LEFT)) OR
setLayout(new FlowLayout(FlowLayout.LEFT,hgap,vgap))
gregorymasila answered the question on January 24, 2018 at 17:42

Answer Attachments

Exams With Marking Schemes

Related Questions