What is the difference between GridLayout and GridBagLayout?

What is the difference between GridLayout and GridBagLayout?

GridLayout class puts all the components in a rectangular grid and is divided into an equal sized rectangles and each component is placed inside a rectangle. 

 The GridBagLayout class is a flexible layout manager that aligns components vertically and horizontally, without requiring that the components be of the same size.

 Each GridBagLayout object maintains a dynamic, rectangular grid of cells, with each component occupying one or more cells, called its display area.GridLayout has the constructors :GridLayout(int rows, int cols) and GridLayout(int rows, int cols, int hgap, int vgap)The major difference between GridLayout and GridBagLayout is that GrigBagLayout supports components of different sizes, and you can specify layout options for each component. 

 Use the GridBagLayout when you need tabular layouts (or layouts that can be thought of as matrices) and when it is important to specify the resizing behavior of each component.

Date:2013-01-09 00:00:00

Post Your Answers

User Email:

User Name:

Related Java Subjective Links

Java Subjective interview questions and answers for experienced and fresher