Hi Payal, In your first two codes you are running into the difference between LayoutManager and LayoutManager2. The containers that implement LayoutManager2 require constraints to be supplied in order to perform the layout. In your first code example, you have not supplied any constraints while adding your components, which is not required by FlowLayout. Then you switch your layout to BorderLayout and the layout doesn't have any constraints for the components. Therefore you see no components being layed out! In your second code example you are doing the opposite. In that case the FlowLayout just ignores your constraints and doesn't its own layout. Your last question regarding GridLayout. The reason for the name is that the entire contents is divided up into equal sized grids. There will always be the number of rows and cols that you specify in the creation. There are specific rules on what will happen if you add more components then you have grids. Please see the API documentation for that explanation. NOTE: GridBagLayout will allow you to have any number of grids of any size in a layout! Regards, Manfred.
For your first question it is about new layout querying the previous layout regarding the components added to it. The layouts implementing Layoutmanager will query the previous layout. i.e flow, Grid layouts implementing LayoutManager2 will not query the previous layout manager regarding the components added. They will start afresh in the screen and will add components only after that. i.e,border, card, gridbag With this reasoning if u analyse your question the answer will be clear. HTH any comments/ corrections welcome.