| Author |
Why is Look and Feel not calling my ButtonUI?
|
Robert Paris
Ranch Hand
Joined: Jul 28, 2002
Posts: 585
|
|
I created a LookAndFeel class that extends the MetalLookAndFeel. The only thing it really overrides is the ButtonUI. It does the following: Then in the ButtonUI class, I have a "System.out.println" in every method, yet nothing prints out. Any idea what's wrong?
|
 |
Nathan Pruett
Bartender
Joined: Oct 18, 2000
Posts: 4121
|
|
|
Did you remember to implement a "public static ComponentUI createUI( JComponent c )" method in your class? Check out the JavaDoc on this method... you have to implement it in every ComponentUI subclass for it to get installed correctly.
|
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
|
 |
Robert Paris
Ranch Hand
Joined: Jul 28, 2002
Posts: 585
|
|
yes, I have:
|
 |
Robert Paris
Ranch Hand
Joined: Jul 28, 2002
Posts: 585
|
|
|
Is the problem one of loading? I have the look and feel classes on the classpath - should they be in the extensions (ext) folder?
|
 |
Robert Paris
Ranch Hand
Joined: Jul 28, 2002
Posts: 585
|
|
OK, it's not the loading issue. I put it in the ext folder and it still didn't work. Here's what's weird though: When I explicitly called jbutton.setUI( ( ButtonUI ) MyButtonUI.createUI( jbutton ) ) it worked! The button took my class, appeared properly and all the system.out's printed! Argh! So why is the LookAndFeel not properly installing it? Any ideas what I'm doing wrong?
|
 |
Nathan Pruett
Bartender
Joined: Oct 18, 2000
Posts: 4121
|
|
OK... are you telling the application that you want to use your look and feel? You can also tell Java to make your look and feel the default... make a swing.properties file in your $JAVA_HOME/jre/lib directory, put the following line in it - And make sure your classes are on the default classpath (or ext directory).
|
 |
Robert Paris
Ranch Hand
Joined: Jul 28, 2002
Posts: 585
|
|
Thanks for the reply. Yes, it is definitely installing my look and feel class because it returns the name of my L&F class when I do: HOWEVER, when I do the following, it returns the metal look and feel class: What's weird is the look and feel class I have seems to be ok, because the following code installs it for the button: Any idea what's wrong?
|
 |
Nathan Pruett
Bartender
Joined: Oct 18, 2000
Posts: 4121
|
|
Here's the (really barebones) test code I've made to test stuff out, and it's working... The ButtonUI class : The MyPlaf class : [ January 28, 2004: Message edited by: Nathan Pruett ]
|
 |
Robert Paris
Ranch Hand
Joined: Jul 28, 2002
Posts: 585
|
|
|
Thanks!! It works. The problem was that I wasn't implementing paint(). All the java.sun.com tutorials never mentioned implementing paint(), but if you don't, it won't use your button UI. I had only implemented update() instead of paint (and let it use MetalButtonUI's paint method) and for some reason that kept it from using my UI.
|
 |
 |
|
|
subject: Why is Look and Feel not calling my ButtonUI?
|
|
|