Get premium membership and access questions with answers, video lessons as well as revision papers.

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


Next: Explain the difference between the AWT components and the Swing Components using examples
Previous: Using a code snippet show how to set the layout of a user interface.

View More Computer Science Questions and Answers | Return to Questions Index


Learn High School English on YouTube

Related Questions