Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AWT FlowLayout to BorderLayout

 
Bijesh Krishnadas
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should only set the layout on your container once... and preferably before you start adding components to it...
 
Bijesh Krishnadas
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic