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

Posted on 2006-07-17
Last Modified: 2013-11-23
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"

Question by:mitchguy
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 4
  • +1
LVL 35

Accepted Solution

girionis earned 30 total points
ID: 17121883
> 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.

Author Comment

ID: 17121980
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?
LVL 86

Expert Comment

ID: 17121986
>>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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 86

Assisted Solution

CEHJ earned 20 total points
ID: 17122003
LVL 35

Expert Comment

ID: 17122028
> 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.

LVL 35

Expert Comment

ID: 17122040
> 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)?

Author Comment

ID: 17122096
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
LVL 86

Expert Comment

ID: 17122137
>>I've uncommented the package statement at the top,

That's the reason for the error probably

Author Comment

ID: 17122163
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.
LVL 86

Expert Comment

ID: 17122719
You need the classes all to be in the correct file system hierarchy according to their package specification
LVL 30

Expert Comment

by:Mayank S
ID: 17129906
Make sure your class-path is set up correctly too:

Author Comment

ID: 17141899
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

LVL 86

Expert Comment

ID: 17142158

The accepted answer was actually incorrect (no offence i hope g. ;-))
LVL 35

Expert Comment

ID: 17144080
Actually, technically it was correct :)

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question