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

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>BlueButtonUI.java:165: 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

//package william.swing.plaf.blue;

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,i.top,b.getWidth()-(i.right+i.left),b.getHeight() - (i.bottom + i.top));
    //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       = "william.swing.plaf.blue.";
    Object[] classes = {
         "ButtonUI"  , pkg + "BlueButtonUI"

Question by:mitchguy
  • 5
  • 4
  • 4
  • +1
LVL 35

Accepted Solution

girionis earned 30 total points
ID: 17121883
> C:\Documents and Settings\sean\Desktop\BluePlaf>BlueButtonUI.java:165:
> 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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 java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown 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,
package william.swing.plaf.blue;
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
javap not working 8 58
throw exception 21 58
by zero exception 10 52
ejb example issues 3 21
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

808 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