• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Why is Look and Feel not calling my ButtonUI?

 
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, I have:
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic