This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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:
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.