I have an uneditable JEditorPane on which I have set the background color to the background color of the containing component to give it that "non-editable" feel. The application allows changing of Look and feels between the operating system default and several other Metal themes. My problem is that when I change from one metal theme to another, the background color is not properly changed. Instead, it is set to white. However, if you change from one Look and feel (ie a Metal theme) to another look and feel (the OS default) or vice versa, the background color is set properly. When I change themes, I first set the look and feel in the UIManager and then use the following line of code to update the frame containing the JEditorPane I have tried overriding the repaint() and updateUI() methods in the containing Frame and setting the background color of the JEditorPane to the proper color right after the call to the super method. I have also tried subclassing JEditorPane and overriding the repaint() and updateUI() methods as well. But neither work. Somewhere, something is setting the background back to white and I have no idea where. Anyone have any suggestions? This is really annoying... Oh, also, same results on both 1.3.1 and 1.4
I'm not sure of your design, but I was able to get the editor pane of the theme example on CodeVault to reflect the color of the taskbar by adding a paint() method to the HTMLDisplay class (a JScrollPane that holds a JEditorPane) like this:
If I set the color directly in the constructor to a Color (like Color.lightGray) it would stay. If I set it to a color from MetalLookAndFeel, it would change to white when the theme changed. I'm not sure why it does this...
Hopefully you can understand what I'm doing... it's confusing even to me...
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Joined: Jul 17, 2002
I overrode the paint method in my panel containing the editor pane as you did above and it now seems to work. I have no idea what was causing the background to change to white. Thanks for your help!