Thus spake Alexander Potochkin: > Hello Gentlemen > > The truth is that L&F can completely ignore the background and > foreground properties > > see JComponent.setBackground() javadoc: > > * It is up to the look and feel to honor this property, some may > * choose to ignore it. > > So for reliable implementation I'd recommend to choose another technique > > You may be interested in this blog > http://polygoncell.blogspot.com/2008/07/validation-module-for-swing-applicati > on.html > > Thanks > alexp Thanks for the reply, but the technique in the blog post seems only to show how you'd decorate a component of type X which is being used as in the role of a component of type X. It doesn't address at all the problem of using a component of type Y in the role of a component of type X.
The concrete problem I faced was that I needed a label which would have fully-justified text that would reflow when resized. So far as I was able to tell, there is no way to do this with JLabel. On the other hand, it's not terribly hard to subclass a JTextPane to get the text behavior I want. However, then I have the problem that a JTextPane doesn't look like a JLabel in some LAFs. I thought that I could overcome this by getting the foreground and background colors for JLabel from UIManager, and then setting those on my custom JTextPane. But setBackground() isn't guaranteed to work in all LAFs, and it just happens that the one LAF where I absolutely want it to work (GTK) is one where it doesn't. What I see as the fundamental problem here is that component classes and component roles are treated as identical. It should be possible to tell Swing that component X has the role Label, and therefore paint it like one. This should not depend on component X being a JLabel, as that ties the role to the implementation. Am I making sense here? I still don't see my way through this. -- J.