Hello friends After Successful post on difference b/w swing and awt we are going to post on Different types of layouts used in Swing.First thing let me tell you what is layout?Layout allows you to adjust component on display screen in platform independent way.The standerd java development kit provides five types of layouts.which are as shown below.
1:-flow layout
2:-greed layout
3:-border layout
4:-card layout
5:-gridbag layout
Now let us understand each layout class with appropriate example
1:-FLOW LAYOUT:-
When you add any component to the screen they flow from left to right and top to bottom based on the width of the screen and in which order they are added to the screen.Suppose you change the size of screen then all component's flow will change according to new height and width of the screen.
Here is the example how you can add the flow layout
2:-GRID LAYOUT:-
Grid layout arranges all components in row's and column's.Now in your mind there is Question that order of added component is matters or not So answer is yes order of added components is manners always.Suppose you added first component then it is stored at (0,0)
next component is stored at(0,1) and so on...
Now How many number of Rows and columns in Grid layout so there is some possibilities which are as given bellow.
1:- Suppose no of rows are specified then no of
columns=no of components / no of rows
2:-Suppose no of columns are specified then no of
rows=no of components / no of columns
3:-No of column is ignored unless the number of rows is zero.
Right now i am sure that you are going to confused about size of component's Don't confused about it because all components are resized automatically to fit in Row - Column Area.
3:-BORDER LAYOUT:-
Border layout provides five areas for hold the components which are named after the four different border of the screen north , east , west , south and center.As we seen above that in both layout order of added element is affects the layout but in border layout order in which component is added in layout is not matters but whenever you add new component you have to specify the place of component.
Here is the code how to add border layout in swing.
4:-CARD LAYOUT:-
Card layout class manages the two or more then two components which are shared the same display screen.For example tabbed menu.
5:-GRIDBAG LAYOUT:-
Grid bag layout is little similar to grid layout.In Grid bag layout components are arranged in rows and columns as in grid layout but difference is in gridbag layout size of rows and columns are not fixed it may have different sizes to all rows and columns This layout manager also provides the facility to merge two or more rows or columns
So friends these are all layout managers which are used in JAVA swing.If you have any Question related to this topic or any topic in java then feel free to ask the question in comments Have a nice day.
1:-flow layout
2:-greed layout
3:-border layout
4:-card layout
5:-gridbag layout
Now let us understand each layout class with appropriate example
1:-FLOW LAYOUT:-
When you add any component to the screen they flow from left to right and top to bottom based on the width of the screen and in which order they are added to the screen.Suppose you change the size of screen then all component's flow will change according to new height and width of the screen.
Here is the example how you can add the flow layout
Grid layout arranges all components in row's and column's.Now in your mind there is Question that order of added component is matters or not So answer is yes order of added components is manners always.Suppose you added first component then it is stored at (0,0)
next component is stored at(0,1) and so on...
Now How many number of Rows and columns in Grid layout so there is some possibilities which are as given bellow.
1:- Suppose no of rows are specified then no of
columns=no of components / no of rows
2:-Suppose no of columns are specified then no of
rows=no of components / no of columns
3:-No of column is ignored unless the number of rows is zero.
Right now i am sure that you are going to confused about size of component's Don't confused about it because all components are resized automatically to fit in Row - Column Area.
3:-BORDER LAYOUT:-
Border layout provides five areas for hold the components which are named after the four different border of the screen north , east , west , south and center.As we seen above that in both layout order of added element is affects the layout but in border layout order in which component is added in layout is not matters but whenever you add new component you have to specify the place of component.
Here is the code how to add border layout in swing.
4:-CARD LAYOUT:-
Card layout class manages the two or more then two components which are shared the same display screen.For example tabbed menu.

Grid bag layout is little similar to grid layout.In Grid bag layout components are arranged in rows and columns as in grid layout but difference is in gridbag layout size of rows and columns are not fixed it may have different sizes to all rows and columns This layout manager also provides the facility to merge two or more rows or columns
So friends these are all layout managers which are used in JAVA swing.If you have any Question related to this topic or any topic in java then feel free to ask the question in comments Have a nice day.



No comments:
Post a Comment