<Swing Dev> Background/Foreground colors and Gtk Look and Feel
Joel Uckelman
uckelman at nomic.net
Fri Jan 23 20:10:43 UTC 2009
Thus spake Joshua Marinacci:
> If we wish to support custom components that try to fit in with the
> native look and feels (which I think is your goal, right? To use a
> textpane for a fancy label?),
Yes, that is my goal.
> then the look and feel should pre-
> populate the defaults table with the right colors. Then other 3rd
> party code and query that table when trying to do the right thing.
> This still means that the native L&F can ignore setBackground, but at
> least you'll be able to make your own code respect colors properly.
>
> - Josh
If I can't call setBackground(), though, how do I tell the JTextPane
what color its background should be? Getting the Color I want is no
problem---I can fetch that with UIManager.getColor("Label.background")
---what I don't see now is what I'm supposed do with that once I have
it. I don't want to change the background color for all JTextPanes,
so calling setColor on "TextPane.background" is no good. Overriding
paintComponent() is of no use because I need super.paintComponent() to
paint the text for me, but it also paints the background. I can't
subclass the UI delegate, because the user might be using some L&F I
don't even have myself. Making my component non-opaque only works if
I know that its parent already has the same background color as a
JLabel would have.
I see no way to do what I'm trying to do if I can't use setBackground()
for it. What am I missing here?
--
J.
More information about the swing-dev
mailing list