[ajug-members] Swing and garbage collection
donald_bleyl at hotmail.com
Wed Jun 30 22:32:19 EDT 2004
A common idiom (for lack of a better word) with Swing apps is to have one
parent JFrame, a
lightweight class w/ main method for bootstraping the program (and no
fields), and a few helper classes that resemble SwingUtilities to manage
functionality that doesn't belong in any one class. An example would be a
WindowUtilities class that provides a center(Window) function. Whether you
use Singleton or static methods is an implementation detail.
The helper classes tend to add some generic functionality and not much
state. Similarly, a resource class can be used to externalize strings, load
icons, etc. For persisting
user preferences, checkout the Preferences API, which is easy to use and
stores info in the
registry when used on Windows. Also, if you are doing Swing, it's essential
to get your head around
the threading issues.
Foxtrot is a library that makes Swing threading easier, and is easy to use
The documentation describes the catch 22's of Swing threading.
Also,you should use setVisible(boolean) instead of show/hide, which are
deprecated as of 1.1.
>I have a swing application that is started by running a class called
>MainApp. The class has a main method that creates an object of itself,
>creates a number of different JFrames and populates a few of its own
>fields with various objects. It's never meant to be seen...more of a
>common entry way into the application.
>The problem is that I'd like it to remain in scope, so that the fields
>that it instantiates are accessible for the entire lifetime of the
>application. This is because it creates a few common resources ( a system
>tray icon if it's run on Windows, for example).
>What's the accepted standard for persisting things like this in swing?
>What is this even called, so that I might google efficiently? Currently,
>as soon as the execution thread has passed through it, it's gone. I tried
>causing it to extend JFrame and calling objectname.hide(), but no luck,
>still garbage collected.
>Thanks for the help!
>ajug-members mailing list
>ajug-members at ajug.org
-->The following solicitation has been imposed by msn:
FREE pop-up blocking with the new MSN Toolbar get it now!
More information about the ajug-members