File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Custom LookAndFeel and JTable problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Custom LookAndFeel and JTable problem" Watch "Custom LookAndFeel and JTable problem" New topic

Custom LookAndFeel and JTable problem

Bartek Myszkowski
Ranch Hand

Joined: Feb 03, 2009
Posts: 44

I am trying to create custom Look And Feel by extending BasicLookAndFeel and I would like to use JTable but I am not able to do so.

Firstly I did not create any class that extends BasicTableUI because I thought that the basic one should be used when i set my LAF, but when i want to create JTable this exception is thrown:so i have put this in UIDefaults table: "TableUI.selectionBackground", Color.RED and I have created MyTableUI that extends BasicTableUI (and added it to UIDefaults table) but same error occured.
I have also tried to create MyTableUI that extends MetalTableUI but it did not help.
I have read Napkin LAF sourcecode a bit but found nothing helpfull.

I have noticed that if i comment setting MyLookAndFeel and default one is used it works fine, so my mistake is somewhere in my LAF...

Sourcecode with isolated problem has been attached:
Rob Spoor

Joined: Oct 27, 2005
Posts: 20275

It took me a while to find out, but for component specific UI properties you need to use initComponentDefaults; furthermore, UIManager.getColor returns null if the property is not a Color object.

Furthermore, the property is called Table.selectionBackground - not TableUI.selectionBackground.

With this fixed class it works for me:

I could leave out initSystemColorDefaults, but I included it to show you a mistake you made: you forgot to call super.initSystemColorDefaults. That didn't fix the problem, even with the TableUI / Table fix though, so I removed that part completely.

How To Ask Questions How To Answer Questions
Bartek Myszkowski
Ranch Hand

Joined: Feb 03, 2009
Posts: 44
Your fix also works for me

Thank You Rob!
I agree. Here's the link:
subject: Custom LookAndFeel and JTable problem
It's not a secret anymore!