Windows Look & Feel for applet?

Discussion in 'Java' started by Ramon F Herrera, Aug 3, 2003.

  1. Is it possible to use the Windows Look & Feel in an applet?

    The following line changes the default (Metal) look and feel
    only when I run my applet from JBuilder:

    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

    However, when the applet runs from the web server, under the
    Netscape plugin, I still get the Metal look & feel. I guess
    I should upload a file to the server and create a directory
    tree such as:

    com/sun/java/swing/windows/...

    but I am not sure about the details. Is this the correct
    solution? Where do I get the file(s) above?

    TIA,

    -Ramon F. Herrera
     
    Ramon F Herrera, Aug 3, 2003
    #1
    1. Advertising

  2. Ramon F Herrera

    Roedy Green Guest

    On 2 Aug 2003 18:56:27 -0700, (Ramon F Herrera)
    wrote or quoted :

    >UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");


    The one fact you may be unaware of is that MS considers its look and
    feel proprietary as does Apple. Thus the Java Windows look and feel
    is only available on Windows and the Mac look and feel is only
    available on the Mac.

    You can defang that using a trick explained at
    http://mindprod.com/jgloss/laf.html


    If both are running under windows, make sure the browsers and JVM's
    being used are the latest. You can check in the Java console.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Aug 3, 2003
    #2
    1. Advertising

  3. Ramon F Herrera

    Gary Thomas Guest

    I think you're probably looking for this:

    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

    On Windows, you get Win look and feel, OSX you get Apple's look and
    feel, etc.

    Be sure to call it before you create your UI components, I seem to
    remember I had problems calling it afterwards.


    Take care,

    Gary

    Ramon F Herrera wrote:

    > Is it possible to use the Windows Look & Feel in an applet?
    >
    > The following line changes the default (Metal) look and feel
    > only when I run my applet from JBuilder:
    >
    > UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    >
    > However, when the applet runs from the web server, under the
    > Netscape plugin, I still get the Metal look & feel. I guess
    > I should upload a file to the server and create a directory
    > tree such as:
    >
    > com/sun/java/swing/windows/...
    >
    > but I am not sure about the details. Is this the correct
    > solution? Where do I get the file(s) above?
    >
    > TIA,
    >
    > -Ramon F. Herrera
     
    Gary Thomas, Aug 3, 2003
    #3
  4. "Gary Thomas" <> wrote in message
    news:rU1Xa.33349$Bp2.5315@fed1read07...
    > I think you're probably looking for this:
    >
    > UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    >
    > On Windows, you get Win look and feel, OSX you get Apple's look and
    > feel, etc.
    >
    > Be sure to call it before you create your UI components, I seem to
    > remember I had problems calling it afterwards.


    There is a solution to that problem, the code
    (I was given) can be found in the PhySci program
    source, but I forget what the solution is right at this
    moment.

    Check the PhySci source if you have to call the
    'setL&F' after the GUI appears.

    --
    Andrew Thompson
    http://www.lensescapes.com/
    http://www.physci.org/
    http://www.1point1c.org/
     
    Andrew Thompson, Aug 3, 2003
    #4
  5. "Andrew Thompson" <> writes:

    > There is a solution to that problem, the code
    > (I was given) can be found in the PhySci program
    > source, but I forget what the solution is right at this
    > moment.


    You call SwingUtilities.updateComponentTreeUI() for each root
    component (JApplet, JFrame, JWindow or JDialog).
     
    Tor Iver Wilhelmsen, Aug 3, 2003
    #5
  6. Roedy Green <> wrote in message news:<>...
    > On 2 Aug 2003 18:56:27 -0700, (Ramon F Herrera)
    > wrote or quoted :
    >
    >UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    >
    > The one fact you may be unaware of is that MS considers its look and
    > feel proprietary as does Apple. Thus the Java Windows look and feel
    > is only available on Windows and the Mac look and feel is only
    > available on the Mac.
    >


    That is indeed an interesting tip. I didn't realize that.
    In my particular case, however, all I want is the Windows
    users (IE & Netscape) to be able to have a Windows L&F.

    I have even tried the suggestion from another reader:

    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

    but every time I connect my applet runs from the web server,
    I get the metal L&F. My latest guess is that perhaps I am
    placing the line above in the wrong method (now it is in main()).

    > If both are running under windows, make sure the browsers and JVM's
    > being used are the latest. You can check in the Java console.


    I am running the latest & greatest (but not beta) but still
    unable to get the Windows L&F...

    Thanks,

    -Ramon
     
    Ramon F Herrera, Aug 3, 2003
    #6
  7. (Ramon F Herrera) writes:

    > but every time I connect my applet runs from the web server,
    > I get the metal L&F. My latest guess is that perhaps I am
    > placing the line above in the wrong method (now it is in main()).


    Er, main() isn't called when you run as applet. Place it in the
    constructor or init().
     
    Tor Iver Wilhelmsen, Aug 3, 2003
    #7
  8. Ramon F Herrera

    Roedy Green Guest

    On 3 Aug 2003 09:50:38 -0700, (Ramon F Herrera)
    wrote or quoted :

    >I am running the latest & greatest (but not beta) but still
    >unable to get the Windows L&F...


    I know Metal L&F works because I can run CyberView Plus either as an
    application, JWS or JApplet with a variety of LAFs. I am pretty sure I
    have run this on IE, Opera, Netscape and Mozilla successfully.

    First thing in your init method put this code exactly as written.

    UIManager.setLookAndFeel( new
    javax.swing.plaf.metal.MetalLookAndFeel() );

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Aug 3, 2003
    #8
  9. "Ramon F Herrera" <> wrote in message news:...
    >
    > I have even tried the suggestion from another reader:
    >
    > UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    >
    > but every time I connect my applet runs from the web server,
    > I get the metal L&F. My latest guess is that perhaps I am
    > placing the line above in the wrong method (now it is in main()).


    If you're running from an applet, you need to set the L&F from
    the applet's init method. Make sure the code is actually getting
    invoked by doing some debug output in the appropriate places.
    Perhaps the below method will be useful to you. It has modest
    amounts of Swing mojo in it. Adapt as needed.


    Marshall
    ------------------------


    /**
    * <p>This method will set the Look and Feel to be whatever the user
    * last selected (as stored in the Prefs object) or the System
    * default look and feel if there's no saved value.
    * @param component the root component (probably the app window) to
    * change the look and feel of.
    * @param prefs the Prefs object that was used to store the
    * user's look-and-feel choice.
    */
    public static void restoreLookAndFeel(Component component,
    Prefs prefs)
    {
    String className;
    className = prefs.get(preferenceKey, null);
    if (className == null)
    {
    className = UIManager.getSystemLookAndFeelClassName();
    }

    try
    {
    UIManager.setLookAndFeel(className);
    SwingUtilities.updateComponentTreeUI(component);
    }
    catch (Exception e)
    {
    // best effort is good enough here.
    }

    }
     
    Marshall Spight, Aug 4, 2003
    #9
  10. Ramon F Herrera

    kjava

    Joined:
    Sep 26, 2007
    Messages:
    1
    Solved

    I was experiencing the same exact problem, but I was able to resolve it by setting the look and feel in the static{} class initializer:

    Code:
        static {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
     
    kjava, Sep 26, 2007
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marina
    Replies:
    3
    Views:
    399
    Marina
    Jan 28, 2004
  2. Srikanth
    Replies:
    1
    Views:
    11,307
    IchBin
    Dec 3, 2005
  3. Ken Cox [Microsoft MVP]

    look and feel windows XP for menu bar

    Ken Cox [Microsoft MVP], Sep 8, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    449
    Seth Bourne
    Sep 9, 2006
  4. Replies:
    0
    Views:
    173
  5. Replies:
    4
    Views:
    212
    Andreas Leitgeb
    Oct 12, 2013
Loading...

Share This Page