I am trying to set the look and feel (LAF) of a Java applet that is used via a web browser. I wish to set the system default LAF, but when loaded in a browser, the applet returns to the Metal LAF. When I run it as a stand-alone applet, the LAF is applied correctly. The only item I am showing the user is a JFileChooser. I have tried a number of methods to overcome this including:
1) Override the applet's start() method:
@Override
public void start() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(this);
System.out.println("LOOK AND FEEL SET!");
}
catch (Exception ex) {
System.out.println(ex);
}
}
2) Set it in the static initializer of the applet class:
static {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
System.out.println("LOOK AND FEEL SET!");
}
catch (Exception ex) {
System.out.println(ex);
}
}
3) Set it in the constructor of the applet:
public MyApplet() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(this);
System.out.println("LOOK AND FEEL SET!");
}
catch (Exception ex) {
System.out.println(ex);
}
}
I am using Java 6, but targeting Java 5 on Windows. In every case, LOOK AND FEEL SET! gets printed to the console, so I know that it set it without throwing an exception. This happens irrespective of browser (using Firefox 3.6 and IE7). Why is it doing this and how can I get it to respect the LAF I designate?