• 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

About Component.setSize()

 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to hear confirmation or denial of the following:
For AWT
a)setSize doesn't work for a component to be added to a container unless is overriden and implemented to supply the value that getPreferred returns.
b)setSize works for Containers. But if the size requested is near the needed one to lay out its components, or less than that, it is ignored.
c) a and b are true regardless the LayoutManager is Border/Flow/Card/Grid/GridBag
It follows an example to play with it and to help to answer the previous questions
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I forget to ask the following point
d)setSize has no efect even if the component is already shown.
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have found a reply in the AWT Sun Forum:
"setSize(), setLocation() and setBounds() won't work when the LayoutManager is other than null."
Given that all the LayoutManagers in the AWT use getpreferredSize (subjected to diferent constraints each of them) this is the method to OVERRIDE!! to change the size of a component to be added to a Container.
reply
    Bookmark Topic Watch Topic
  • New Topic