• 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

Layout Manager

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey all,
If no layout manager is set before adding components and then after adding components, a default manager is explicitly set using setLayout() method, then all the components didn't show up, as the following example:

Could anyone explain why? Thanks.
Luk
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i played around with the code, the only thing i can think of is that the by setting the new layout it overrides the previous layout.
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A frames default layout is BorderLayout, so when you explicitly state setLayout(new BorderLayout()) you are not really doing anything.
The reason all the components don't show up is because with BorderLayout, if you don't specify where to place the items, they will be placed in the "center" position. You didn't specify where you wanted them, so they were all placed in the center position. Since the center position fills the area after NORTH, EAST, SOUTH, and WEST are filled (which in your case there isn't any) only one button will show. Should be the last one you added also.
Change your code from setLayout(new BorderLayout()) to setLayout(New FlowLayout()) and see what you get.
Bill
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I played with the code some also and it does appear that when you set a new layout it overrides the previous layout, but when you set new BorderLayout it erases everything.
What you can take from this is that you shouldn't do this. You should set your layout manager first and then add all the buttons and components that you want.
Bill
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In addition, If you remvoe setLayout(new BorderLayout()) code line, you should be able to see last added component (button having caption center). Remember this is cover all your form. and all other button would be beneath this, those you wont be able to see without specifying position to add. Hope this will help.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yah i am also confused with this thing.Except for the BorderLayout assigning new Layout doesn't wipe the previous components.But why is it so???

[This message has been edited by sandeep bagati (edited March 03, 2001).]
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you change LayoutManager to BorderLayout, GridBagLayout, CardLayout you will not get any componenet visible. If you want to make componenet you have to add components again.
But if you change LayoutManager to FlowLayout, GridLayout you get components according to these Layouts.
For eg if LayoutManager is FlowLayout and you change it to BorderLayout you will get nothing.
FlowLayout and GridLayout takes there components list from the container but BorderLayout etc keep their own list so when you change fro Border to Flow, FlowLayout Manager gets old components list from container but in case of Border it is not taking that list but using own(0 components) so there is nothing to lay.
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
To make a long story short:
LayoutManager - layout any added components
LayoutManager2 - layout new components only (uses constraints)
Regards,
Manfred.
 
sandeep bagati
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks mohan
 
Can you hear that? That's my theme music. I don't know where it comes from. Check under this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic