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 / December 2004

Tip: Looking for answers? Try searching our database.

Updating LAF after startup

Thread view: 
IchBin - 27 Dec 2004 18:52 GMT
Hello All,

Could some one point me to information for changing the LAF after the
initial LAF has been loaded in a java application? I did see the code
for 'SwingSet 2' in the Java demo subdirectory. I am having a hard time
implementing that in my code.

Thanks in Advance...
IchBin
__________________________________________________________________________

'The meeting of two personalities is like the contact of two chemical
substances:  if there is any reaction, both are transformed.'
-  Carl Gustav Jung,  (1875-1961),  psychiatrist and psychologist
IchBin - 27 Dec 2004 19:46 GMT
Forgot, here is a snippet the code I am trying to run presently... Why
would this nor work? Thought that the
SwingUtilities.updateComponentTreeUI() would update of the the objects
under frame.

    static void setSwingLAF(JFrame frame, String targetTheme) {
        try {

            if (targetTheme.equalsIgnoreCase(Native)){

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                SwingUtilities.updateComponentTreeUI(frame);
                return;
            }
            if (targetTheme.equalsIgnoreCase(Java)){

UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
                SwingUtilities.updateComponentTreeUI(frame);
                return;
            }
            if (targetTheme.equalsIgnoreCase(Motif)){

UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
                SwingUtilities.updateComponentTreeUI(frame);
                return;
            }

            if (targetTheme.equalsIgnoreCase(BrownSugar))
                Plastic3DLookAndFeel.setMyCurrentTheme(new DarkStar());
            else if (targetTheme.equalsIgnoreCase(DesertRed))
                Plastic3DLookAndFeel.setMyCurrentTheme(new DesertRed());
            else if (targetTheme.equalsIgnoreCase(DesertYellow))
           else
                Plastic3DLookAndFeel.setMyCurrentTheme(new SkyYellow());
            Plastic3DLookAndFeel.setHighContrastFocusColorsEnabled(true);
            UIManager.setLookAndFeel(new Plastic3DLookAndFeel());
            UIManager.put(com.jgoodies.plaf.Options.DEFAULT_ICON_SIZE_KEY,
                    new Dimension(18, 18));
            SwingUtilities.updateComponentTreeUI(frame);

        } catch (Exception e) {
            errorMessage(e);
        }
    }

Signature

Thanks in Advance...
IchBin
__________________________________________________________________________

'The meeting of two personalities is like the contact of two chemical
substances:
 if there is any reaction, both are transformed.'
-  Carl Gustav Jung,  (1875-1961),  psychiatrist and psychologist

IchBin - 27 Dec 2004 20:05 GMT
Not to be only a singular and circular dialectic ...

Sorry my code DOES work..

Only if I pass the correct component.

Signature

Thanks in Advance...
IchBin
__________________________________________________________________________

'The meeting of two personalities is like the contact of two chemical
substances:
 if there is any reaction, both are transformed.'
-  Carl Gustav Jung,  (1875-1961),  psychiatrist and psychologist

Larry Barowski - 27 Dec 2004 20:07 GMT
> Forgot, here is a snippet the code I am trying to run presently... Why
> would this nor work? Thought that the
> SwingUtilities.updateComponentTreeUI() would update of the the objects
> under frame.

It will, but it may have problems for certain components, and it
won't get owned windows. Also you may need to call validate()
on the frames to see the effects. The usual method to get all
frames and dialogs is something like:

void updateAllUI() {
       Frame[] frames = Frame.getFrames();
       for(int f = 0; f < frames.length; f++) {
          updateComponentTreeUI(frames[f]);
          frames[f].validate();
          Window[] windows = frames[f].getOwnedWindows();
          for(int w = 0; w < windows.length; w++) {
             updateComponentTreeUI(windows[w]);
             windows[w].validate();
          }
       }
    }

where updateComponentTreeUI() could be from SwingUtilities
or your own if the SwingUtilities one gives you problems.

Also keep in mind that any components that are not attached
to a Window will not get updated. So if you have popup menus
or reference components used in rendering others, etc., you
will need to call updateUI() on them manually. Usually you
would do that in the updateUI() method of the enclosing
class (if they are static, this may result in multiple updates,
which won't hurt anything), or by using a global UI update
mechanism with which you can register such components.


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.