Compile error cannot find symbol: method initClassDefaults(javax.swing.UIDefaults)

I've been trying to get an example program I found about making your own PLAF to work, but can't seem to get past this error

C:\Documents and Settings\sean\Desktop\BluePlaf> cannot find symbol
symbol  : method initClassDefaults(javax.swing.UIDefaults)
location: class javax.swing.plaf.basic.BasicButtonUI
1 error

The code I'm trying to compile is below
I've tried adding all of the import statements that i now commented out since it didn't help
The error is on Line 165 and is 9 lines up from the bottom


import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import java.awt.geom.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;
import javax.swing.text.View;
//import javax.swing.plaf.ButtonUI;
//import javax.swing.plaf.basic.BasicLookAndFeel;
//import javax.swing.UIDefaults;
//import javax.swing.plaf.metal.MetalLookAndFeel;

public class BlueButtonUI extends BasicButtonUI {

  //The singleton istance of BlueButtonUI
  static BlueButtonUI b = new BlueButtonUI();
  //Default background and foreground
  Color background;
  Color foreground;
  //There will be only one font for this these buttons
  Font font;

  public BlueButtonUI() {

 //The factory method returns the singleton
 public static ComponentUI createUI(JComponent c) {
      return b;
public void installUI(JComponent c) {
    //Since we know this is a JButton it is safe to cast as an AbstractButton
    AbstractButton b = (AbstractButton)c;

    //Setting the default values from the UIDefaults table
    background = UIManager.getColor("Button.background");
    foreground = UIManager.getColor("Button.foreground");
    font       = UIManager.getFont("Button.font");

    //Checking for user set values for foreground and background before setting them
    //Note that the font compnonent is not checked therefore the value from the UIDefaults table will
    //override the user’s values (This is not recommended) further not all the defaults are set
    if(c.getBackground()==null || (c.getBackground() instanceof UIResource))

    if(c.getForeground()==null || (c.getForeground() instanceof UIResource))
    //Using BasicButtonUI installListeners method to install listeners
    /*Note that there are no keyboard registations, therefore hit any of the keys will not invoke an event*/
//Paints a rounded button that is semi-transparent with lines

public void paint(Graphics g, JComponent c) {
   //Once again it is safe to cast as an AbstractButton because we know it is a JButton
    AbstractButton b = (AbstractButton)c;
   //The ButtonModel holds a lot of the functional state of the button
    ButtonModel model = b.getModel();
   //Casting to a Graphics2D for convenience, this is safew because we know that the g object is really a Graphics2D object
    Graphics2D g2 = (Graphics2D)g;

    //Sets the arcs widths and heights
    int arc_w = (int)c.getHeight()/2;
    int arc_h = arc_w;

    Insets i = c.getInsets();
    //Gets the area for the text and icon to be painted in with respects to the insets
    Rectangle viewRect = new Rectangle(i.left,,b.getWidth()-(i.right+i.left),b.getHeight() - (i.bottom +;
    //the area that the text will be drawn in that will be defined
    //by SwingUtilities.layoutCompoundLabel
    Rectangle textRect = new Rectangle(0,0,0,0);
    //the area that the icon will be drawn in that will be defined
    //by SwingUtilities.layoutCompoundLabel
    Rectangle iconRect = new Rectangle(0,0,0,0);

    //I have opted to set the base font size on the size of the button this will cause the font size to skrink or grow with respect to the button size
    int fontSize = (int)c.getHeight()/3;
      fontSize = 8;
    g2.setFont(new Font(font.getName(),font.getStyle(),fontSize));
    //modify text for display, will add ... if clipped and
    //determine the text area and icon area
    String text = SwingUtilities.layoutCompoundLabel(
            c, g2.getFontMetrics(), b.getText(), b.getIcon(),
            b.getVerticalAlignment(), b.getHorizontalAlignment(),
            b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
            viewRect, iconRect, textRect,
          b.getText() == null ? 0 : b.getIconTextGap());

    //Starting with a BufferedImage because the graphics object from a BufferedImage respects composite overlay directives
    //NOTE the Graphics object passed in to this method does not respect these directives
    BufferedImage buffImg = new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D gbi = buffImg.createGraphics();
    //Retrieving the state of the colors from the component which were set in the installUI method
    Color back = c.getBackground();
    Color fore = c.getForeground();

    //creating a semi-transparent background for the button
    Color bg = new Color(back.getRed(),back.getGreen(),back.getBlue(),127);
    //Defining the color of my borders
    Color wh = Color.WHITE;
    Color gr = Color.GRAY;
    //if button is pressed change the background to dark and switch the border colors (this makes it appear that the button is pressed in)
    if (model.isArmed() && model.isPressed()) {
      Color d = back.darker().darker().darker();
      bg = new Color(d.getRed(),d.getGreen(),d.getBlue(),127);
      wh = Color.GRAY;
      gr = Color.WHITE;

    //set background color
    //lay in the strips
    for(int j=0;j<c.getHeight();) {

//paint button image
    //Draw borders (NOTE a better implementation would have created a borders object)
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setStroke(new BasicStroke(2.0f));
    Arc2D.Double  ar1;
    ar1 = new Arc2D.Double(0,0,arc_w,arc_h,90,90,Arc2D.OPEN);
    ar1 = new Arc2D.Double(c.getWidth()-arc_w,1,arc_w,arc_h,0,90,Arc2D.OPEN);

    ar1 = new Arc2D.Double(c.getWidth()-arc_w,c.getHeight()-arc_h,arc_w,arc_h,270,90,Arc2D.OPEN);
    ar1 = new Arc2D.Double(0,c.getHeight()-arc_h,arc_w,arc_h,180,90,Arc2D.OPEN);

    //painting text
    //draw the text at the x of the textRect and the y textRect plus the font ascent.
    //"The font ascent is the distance from the font's baseline to the top of most
    //alphanumeric characters."(From Java API Doc on java.awt.FontMetrics.getAscent())
    //If there is an icon paint it at the x and y of the iconRect

//Then you just add it to the UIDefaults table
 protected void initClassDefaults(UIDefaults table) {
    //package that the ComponentUI classes belong too
    String pkg       = "";
    Object[] classes = {
         "ButtonUI"  , pkg + "BlueButtonUI"

Who is Participating?
girionisConnect With a Mentor Commented:
> C:\Documents and Settings\sean\Desktop\BluePlaf>
> cannot find symbol
> symbol  : method initClassDefaults(javax.swing.UIDefaults)
> location: class javax.swing.plaf.basic.BasicButtonUI
>     super.initClassDefaults(table);

This means that the superclass' initClassDefaults either does not get any parameters or the parameter you are passing is of the wrong type. Check the documentation to see what the method expects.
mitchguyAuthor Commented:
Well I found the function in the 1.4.2 API
but cannot find it in the Java 5.0 API
in the former it is listed in
javax.swing.plaf.basic.BasicLookAndFeel, which is why I tried using that import statement once

So I guess it's deprecated?

Do you know a replacement function to get it to compile?
>>This means that the superclass' initClassDefaults either does not get any parameters or the parameter you are passing is of the wrong type.

It actually doesn't exist at all. See if the method you mean exists in another package. If it does, you'll need to declare something like

public class BlueButtonUI extends x.y.z.BasicButtonUI
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

> It actually doesn't exist at all. See if the method you mean exists in
> another package. If it does, you'll need to declare something like

Yes you are right, it does not exist at all. It exists in another class, as you showed.

mitchguy I suggest you either extend the BasicLookAndFeel class or try to use another technique to do it.

> Do you know a replacement function to get it to compile?

The issue is not to compile, you could just get rid of this line and it would compile. The issue is to get it working. What happens if you do not initialize it (i.e. get rid of the line)?
mitchguyAuthor Commented:
Well with it commented out I get this error

C:\Documents and Settings\sean\Desktop\BluePlaf>java BlueButtonUI
Exception in thread "main" java.lang.NoClassDefFoundError: BlueButtonUI (wrong name: william/swing/plaf/blue/BlueButtonUI)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at Source)
        at Source)
        at$100(Unknown Source)
        at$ Source)
        at Method)
        at Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)

I've uncommented the package statement at the top,
but it didn't help
>>I've uncommented the package statement at the top,

That's the reason for the error probably
mitchguyAuthor Commented:
I guess I left out some information there, sorry
I originally commented it out, it was the first error I got after downloading it, something
in reference to the package, so I commented it out, until now when the error
was looking for it. So i tried restoring it to it's uncommented original form.
You need the classes all to be in the correct file system hierarchy according to their package specification
Mayank SAssociate Director - Product EngineeringCommented:
Make sure your class-path is set up correctly too:
mitchguyAuthor Commented:
Well as it turns out the example code i obtained was somebody's hacked up version. I found the original, which when looking at the code shows the function with my error in a whole other class i didn't even have. One that implements
BasicLookAndFeel as expected by comments above
Here is the link to the correct  example code


The accepted answer was actually incorrect (no offence i hope g. ;-))
Actually, technically it was correct :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.