This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes AWT FlowLayout to BorderLayout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "AWT FlowLayout to BorderLayout" Watch "AWT FlowLayout to BorderLayout" New topic
Author

AWT FlowLayout to BorderLayout

Bijesh Krishnadas
Ranch Hand

Joined: Aug 08, 2002
Posts: 31
the following code displays no components on execution. can somebody xplain?

when the vice versa, i.e. BorderLayout is changed to FlowLayout, the components are shown...
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

You should only set the layout on your container once... and preferably before you start adding components to it...


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Bijesh Krishnadas
Ranch Hand

Joined: Aug 08, 2002
Posts: 31
actually the code works when i first setLayout(BorderLayout) and then change it to FlowLayout ... see code below ...


the results is a frame with the Buttons are arranged in a line in the order (From left to right) "South","West","East","North" and "Center".
i.e. FlowLayout
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Hmmm... it seems to be something to do with BorderLayout...

Here's some test code I whipped up...



The only layout that can't be changed back is BorderLayout...
Lon Allen
Ranch Hand

Joined: May 24, 2001
Posts: 67
What is the desired effect? Why would you want to change the layout from one to the other? BorderLayout is specific in the way the items are added (the location of the item is one of the arguments). FlowLayout adds the items in the order that they were added in the code. You typically set the layout and then add the items. If you go and change the layout at a later point (after the items have been added) I don't see how you could expect any consistency in the order at that point. What is the reason for going from one layout to the other?
Bijesh Krishnadas
Ranch Hand

Joined: Aug 08, 2002
Posts: 31
there is no specific desired effect i'm lookin for. i just happened to come across the odd behaviour of the BorderLayout n wondered y it's so?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: AWT FlowLayout to BorderLayout
 
Similar Threads
Why the button doesn't appears in the Frame?
java.awt BorderLayout and FlowLayout
Why the button doesn't appear in th frame?
Layout
Why the button doesn't appear in th frame?