File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JEditorPane - background color not properly set when changing metal color theme Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JEditorPane - background color not properly set when changing metal color theme" Watch "JEditorPane - background color not properly set when changing metal color theme" New topic
Author

JEditorPane - background color not properly set when changing metal color theme

Chrissy Simpson
Greenhorn

Joined: Jul 17, 2002
Posts: 22
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
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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...


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Chrissy Simpson
Greenhorn

Joined: Jul 17, 2002
Posts: 22
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JEditorPane - background color not properly set when changing metal color theme
 
Similar Threads
JButton is not displaying the background color
Background problem in Windows XP with Theme
Designing GUIs with cross-platform look and feel
Eclipse editor colors
Help with GridBagLayout resize behaviour