• 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

vallidate(),pack(),doLayout(),repaint() and setSize()

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can somebody describe the differences and relationships among these methods? I have had a very difficult time getting a scrollpane to size correctly.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


doLayout()
call the LayoutManager of the Container that holds the Component on which this message was sent, to layout the Component. Normal programs should not call it directly because it is called when the Container receives the validate message.
validate() mainly intended to be invoked over Containers. Call doLayout on the Components contained by the Container.
pack() on a Container links the Container to its peer. The peer is the native resource for representation on the screen. It does the same to the Components holded by the Container. Also set the sizes to the natural ones. That is those returned by getPreferredSize method. But the size is subjected to LayoutManger oversight.
A Window needs either pack or setSize, after that show or setVisible. The last two also links the Java objects to their peers (as pack does) but they don't set the size.
I have read that setSize, setBounds and setLocation, for Components contained by a Container, only work if the LayoutManager is null.
Calling repaint shedules a call to upgrade in the AWT Painting-Event thread. There is only a thread dedicated to these tasks because otherwise the painting of a Component could be interrupted, and it could be left unfinished. The default implementation for upgrade just clean the Component drawing area and call paint. This method lastly paints the Component.
Any corrections are wellcomed
 
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jose,
you wrote:


pack() on a Container links the Container to its peer. The peer is the native resource for representation on the screen. It does the same to the Components holded by the Container. Also set the sizes to the natural ones. That is those returned by getPreferredSize method. But the size is subjected to LayoutManger oversight.


1)But how about Swing light-weight components?
2)Then I am perplexed I have never read that pack() links to peer. I have never read it about any method...
I always remembered, my books, Sun's API and tutorial, etc. tell:


The pack method sizes the frame so that all its contents are at or above their preferred sizes


"Java Programming Language". SL-275. Student Guide. Sun Microsystems. Revision C.1, September 1999
states on the page 8-19:~
f.pack()
This method tells the frame to set a size that "neatly encloses" the components that it contains. To determine what size to use for the Frame, f.pack() queries the layout manager, which is responsible for the size and position of all components within the Frame().


pack() makes layout of all components in Container while doLayout() of just one specifically....
[This message has been edited by G Vanin (edited November 20, 2001).]
 
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
Hi G
This from Window.pack() API:


Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. If the window and/or its owner are not yet displayable, both are made displayable before calculating the preferred size. The Window will be validated after the preferredSize is calculated.


and this is from Component.isDisplayable() API:


Determines whether this component is displayable. A component is displayable when it is connected to a native screen resource.
A component is made displayable either when it is added to a displayable containment hierarchy or when its containment hierarchy is made displayable. A containment hierarchy is made displayable when its ancestor window is either packed or made visible.
A component is made undisplayable either when it is removed from a displayable containment hierarchy or when its containment hierarchy is made undisplayable. A containment hierarchy is made undisplayable when its ancestor window is disposed.

 
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
Though I said a Container.pack(), but there is no such method. Window.pack() yes it does exits.
 
Guennadiy VANIN
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jose.
I see the consequential line
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic