Windows Look & Feel for applet?

  • Thread starter Ramon F Herrera
  • Start date
R

Ramon F Herrera

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
 
R

Roedy Green

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.
 
G

Gary Thomas

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
 
A

Andrew Thompson

Gary Thomas said:
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.
 
T

Tor Iver Wilhelmsen

Andrew Thompson said:
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).
 
R

Ramon F Herrera

Roedy Green said:
On 2 Aug 2003 18:56:27 -0700, (e-mail address removed) (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
 
T

Tor Iver Wilhelmsen

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().
 
R

Roedy Green

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() );
 
M

Marshall Spight

Ramon F Herrera said:
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.
}

}
 
Joined
Sep 26, 2007
Messages
1
Reaction score
0
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();
        }
    }
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top