Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Swing Look and Feel not working

Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?

Always! Wait. Never. Shut up. Look at this tiny ad.
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic