Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JPanel lifecycle events.

Status
Not open for further replies.

dbleyl

Programmer
Mar 26, 2001
117
0
0
US
I'm interested in creating a data-driven JPanel that can be used in different containers.

In a JDialog, it's easy to manage resources when the dialog is opened (acquire) or closed (release). This allows the
client to create the dialog, use it, dispose it properly and not to have to manage resources.

I am investigating ComponentListener, but I'm not catching the proper events. Currently, I'm stuck with forcing the parent container to manage resources, which appears ok, but ties the JPanel to the parent.

Anyone have an idiom for acquiring and releasing
resources for JPanel?
 
I'm not sure if I'm following... JDialog, being a top-level container, will be able to detect window events; JPanel won't be able to. What resources were you interested in acquiring/releasing? Which would you consider are the "proper events"? <p>Liam Morley<br><A HREF="mailto:"></A><br>&quot;light the deep, and bring silence to the world.<br>light the world, and bring depth to the silence.&quot;
 
This was a strange question. I'm was thinking of COMPONENT_HIDDEN or COMPONENT_SHOWN of ComponentEvent.
If I generalize the question, it may make more sense:
You want to build a composite 'Component' in Swing that presents some data to the user. You'd like to drop this
component into different containers (JPanel, JDialog etc)
and have it manage it's own data, so all the containing
client has to do is properly initialize it.

If this component needs to acquire resources, and later
release them (for ex, opening a DAO and then closing),
then it is cut-and-dry with a JDialog, because it also
has a similar lifecycle: ctor(), dispose(), for example.

This is a bad ex, but:
public void setVisible(boolean vis) {
if (vis) mypanel.load();
super.setVisible(vis);

}
public void dispose() [
mypanel.close();
super.dispose();
}

But what if the components are nested in a JPanel? Where
are the hooks?

I've since solved this issue by changing the data access strategy and catching events from the individual components used to build the composite. But I'm still interested in ideas.





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top