File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Swing Look and Feel not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swing Look and Feel not working" Watch "Swing Look and Feel not working" New topic

Swing Look and Feel not working

John Palmieri

Joined: Jul 05, 2001
Posts: 8
I am having a problem with the look and feel methods. I have a applet that can run either as an applet or an application. If it is run as a application, The code puts the applet into a JFrame.
This works, but the look and feel always seems to be metal. I want the look and feel to be windows. How can I accomplish this ?
This is code that was built with Jbuilder 5 with some additions
from me trying to accomplish what I want. when I switch to Jbuilders UI designer the screen pick up the windows look and feel.
I am using JDK 1.3.
Here is the code...
package untitled29;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
public class Applet2 extends JApplet {
boolean isStandalone = false;
JButton jButton1 = new JButton();
JComboBox jComboBox1 = new JComboBox();
/**Get a parameter value*/
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
/**Construct the applet*/
public Applet2() {
/**Initialize the applet*/
public void init() {
try {
catch(Exception e) {
/**Component initialization*/
private void jbInit() throws Exception {
jButton1.setBounds(new Rectangle(110, 39, 103, 27));
jComboBox1.setBounds(new Rectangle(87, 103, 156, 21));
this.getContentPane().add(jButton1, null);
this.getContentPane().add(jComboBox1, null);
/**Get Applet information*/
public String getAppletInfo() {
return "Applet Information";
/**Get parameter info*/
public String[][] getParameterInfo() {
return null;
/**Main method*/
public static void main(String[] args) {
Applet2 applet = new Applet2();
applet.isStandalone = true;
JFrame frame;
frame = new JFrame() {
protected void processWindowEvent(WindowEvent e) {
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
public synchronized void setTitle(String title) {
String laf = UIManager.getSystemLookAndFeelClassName();
} catch (UnsupportedLookAndFeelException exc) {
System.err.println("Warning: UnsupportedLookAndFeel: " + laf);
} catch (Exception exc) {
System.err.println("Error loading " + laf + ": " + exc);
Frame[] frames = frame.getFrames();
for(int f = 0; f < frames.length; f++) {
Window[] windows = frames[f].getOwnedWindows();
for(int w = 0; w < windows.length; w++) {

frame.setTitle("Applet Frame");
frame.getContentPane().add(applet, BorderLayout.CENTER);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
Matt Hansen
Ranch Hand

Joined: Jul 31, 2001
Posts: 34
I have not worked with applets before. But, when I run this it runs the init method instead of main. Maybe this is normal for applets? Anyway, when I run your code in jBuilder5 the main method is never called so the look and feel is never set.
[This message has been edited by Matt Hansen (edited October 03, 2001).]
glenn mason

Joined: Sep 30, 2001
Posts: 3

main is the starting point for an application; applets have a couple of automatically called methods: init, start, stop, destroy. You could put the PLAF code in a method and call it from both main and init.

getSystemLookAndFeelClassName() returns the Metal classname if it can't find a System one. Whether a system LAF is available depends on your Java install, maybe. Try UIManager.getAuxiliaryLookAndFeels() (returns an array), then getName on each of the LookAndFeel objects in the array. Just to see what LAFs you are getting back?

I agree. Here's the link:
subject: Swing Look and Feel not working
It's not a secret anymore!