posted 24 years ago
Hi,
Whenever the default Layout is changed then the Components will be laid out "only" as per the new layout.
For example, the default Layout for Frames is "BorderLayout" and as per your code, first the default "BorderLayout" is changed to "FlowLayout". Hence, all the 5 Components (buttons) are laid in a single row from Left to Right.
When you change it again to BorderLayout, the Components will not assume the BorderLayout positions. They still occupy the positions as per FlowLayout.
But, you can always change it to any Layout other than the default BorderLayout i.e, you can change the layout from FlowLayout to even GridLayout but not to "BorderLayout" in any case.
I added extra lines to your code to change the layout. You can try this by removing the comment lines...
....
public fra7()
{
setLayout(new BorderLayout());
add(bSouth, "South");
add(bWest, "West");
add(bEast, "East");
add(bNorth, "North");
add(bCenter);
setLayout(new FlowLayout()); // 1 Layout changes
setLayout(new BorderLayout()); // 2 Does not change
setLayout(new FlowLayout()); // 3 Layout changes
setLayout(new BorderLayout()); // 4 Does not change
setLayout(new FlowLayout()); // 5 Layout changes
setLayout(new GridLayout(2, 3)); // 6 Layout changes
setLayout(new FlowLayout()); // 7 Layout changes
setLayout(new BorderLayout()); // 8 Does not change
setSize(200, 200);
setVisible(true);
}
.....
- Suresh Selvaraj
Suresh Selvaraj, (author of JQuiz)<br />SCJP2<br /><a href="http://www.decontconsulting.com" target="_blank" rel="nofollow">www.decontconsulting.com</a>