Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Custom LookAndFeel and JTable problem

 
Bartek Myszkowski
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bartek Myszkowski
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your fix also works for me

Thank You Rob!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic