• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

AWT FlowLayout to BorderLayout

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic