wood burning stoves*
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
Author

Custom LookAndFeel and JTable problem

Bartek Myszkowski
Ranch Hand

Joined: Feb 03, 2009
Posts: 44
Hello,

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
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
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: http://aspose.com/file-tools
 
subject: Custom LookAndFeel and JTable problem
 
Similar Threads
Custom LookAndFeel and JTextArea (functional keys doesn't work)
jtable
Problem with custom look and feel implementation
JTable In JTree
JTable