Refresh Entire UI

J

Jason Cavett

Is there a way to tell a top-level Java Swing component to refresh and
have all of its subcomponents refresh along with it?

The reason I am asking is that I have a skinning/theme system in place
and when the user switches themes, I want it to update on the fly.
This works with some of the components (icons/text/etc), but I can't
seem to get the entire GUI to refresh (trying to do this via
updateUI()).

Any suggestions?
 
D

Daniele Futtorovic

Is there a way to tell a top-level Java Swing component to refresh and
have all of its subcomponents refresh along with it?

The reason I am asking is that I have a skinning/theme system in place
and when the user switches themes, I want it to update on the fly.
This works with some of the components (icons/text/etc), but I can't
seem to get the entire GUI to refresh (trying to do this via
updateUI()).

Any suggestions?

Do you mean you changed the UI delegate of each, or at least some,
Component(s)?

Have you tried invalidate() + validate() on the root Container (e.g. a
JFrame)?
 
K

Knute Johnson

Jason said:
Is there a way to tell a top-level Java Swing component to refresh and
have all of its subcomponents refresh along with it?

The reason I am asking is that I have a skinning/theme system in place
and when the user switches themes, I want it to update on the fly.
This works with some of the components (icons/text/etc), but I can't
seem to get the entire GUI to refresh (trying to do this via
updateUI()).

Any suggestions?

Have you tried any of the validate()/repaint() options?
 
J

Jason Cavett

Do you mean you changed the UI delegate of each, or at least some,
Component(s)?

Have you tried invalidate() + validate() on the root Container (e.g. a
JFrame)?

I did, and that refreshes some of the components (namely, the menus,
the JTree contained within the JFrame, etc). However, it does *not*
refresh the JInternalFrames that I have contained within the parent
JFrame.

It's a little bit confusing. Is there something different about the
JInternalFrames that I'm not understanding?

Thanks for your response.
 
D

Daniele Futtorovic

I did, and that refreshes some of the components (namely, the menus,
the JTree contained within the JFrame, etc). However, it does *not*
refresh the JInternalFrames that I have contained within the parent
JFrame.

It's a little bit confusing. Is there something different about the
JInternalFrames that I'm not understanding?

Sorry, I don't know for sure. Actually, I haven't ever used
JInternalFrames seriously. Knute might be able to tell you better than I.

Are you using a JDesktopPane for the JInternalFrames, as advised? Having
a quick glance at the source code, I don't see anything that might
intercept the invalidation -- the JInternalFrames are added as children
to the JDesktopPane, and consequently should be part of the same
hierarchy. So I don't really know why it doesn't work.

You might want to manually hide and show the JInternalFrames again, to
check whether it's merely a refresh problem.

Then, of course it should be possible to hack around the problem by
gathering, invalidating and validating the JInternalFrames manually. I'd
find that unsatisfying if it were my code, so I merely mention it as a
last resort.
 
A

Andrew Thompson

Is there a way to tell a top-level Java Swing component to refresh and
have all of its subcomponents refresh along with it?

The best way to achieve that seems to be along
the lines of..

...
UIManager.setLookAndFeel( plaf );
// called from JFrame sub-class, the
// 'root' component of the GUI
SwingUtilities.updateComponentTreeUI(this);
...

If that fails for you, I suggest you post an SSCCE
trimmed to just the JDesktopPane, the JInternalFrames
and a menu to select the various default PLAFs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top