This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why is Look and Feel not calling my ButtonUI?

 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, I have:
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic