Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / October 2006

Tip: Looking for answers? Try searching our database.

how and when components get their own size?

Thread view: 
Zaka Ferenc - 21 Oct 2006 17:56 GMT
I've wrote an applet that renders some vector data. Applet's content pane has a JPanel
child as the canvas. Before the first rendering and (paint()-ing) this JPanel needs to
know its' own size to properly caclulate the size of object to be drawn. JApplet has a
BorderLayout, so everithing gets the size automatically.
First access of the applet is working fine. After a stop() and destroy() event (but
without closing the browser) and hitting again the applet's page the applet crashes because
of JPanel.getWidth() and getHeight() returns 0.
( I'm doing everything _after_ the init() and start() using invokeLater() ).

So I'm confused a bit, how and when the layouted components get their size.

After the first paint()? But then how can I calculate the correct sizes of object to be
 drawn? And why does work the applet after the first loading?

(Just a notice: none of my browsers follow the standard of applet's lifecycle events.
Displaying applet's page always causes init() and start(), and moving to another page
always causes stop() and destroy(). And I can't produce a combination of mouse clicks
 that causes a start() without init() or a stop() without destroy().)

Thanks for help,
regards,
Feri
hiwa - 22 Oct 2006 10:03 GMT
> I've wrote an applet that renders some vector data. Applet's content pane has a JPanel
> child as the canvas. Before the first rendering and (paint()-ing) this JPanel needs to
[quoted text clipped - 18 lines]
> regards,
> Feri
getWidth(), getHeight() and getSize() et al returns non-zero values
after the component become visible. Often used idiom is to call
them in paint() or paintComponent() method of custom component.
In order to force particular size, use setPreferredSize and/or
override the getPreferredSize() method. Both methods works only
for Swing components.
Zaka Ferenc - 22 Oct 2006 11:16 GMT
Thank you, hiwa.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.