Skip to main content

JTextArea background color under GTK Look and Feel

8 replies [Last post]
dglasser
Offline
Joined: 2003-06-13
Points: 0

I have a JTextArea that I'm using sort of like a JLabel that wraps text. It's disabled and non-editable. In its updateUI() method, after calling super.updateUI(), I call UIManager.getColor("Panel.background") to get the background color.

In most LAFs, this does what I want, but in the GTK LAF, this returns null. So I call getParent().getBackground() and that returns RGB:214/214/214, which is the light grey that GTK uses for panels. I explicitly set this as the background in the JTextArea, but it always appears white. I've even tried every possible combination of the editable, enabled and opaque properties, but nothing seems to work. I've used debugging output to verify just before the ancestor JDialog is displayed that the JTextArea's background is 214/214/214.

Does anyone have any idea how I can work around this? This is the new GTK LAF in JDK 1.4.2 that I'm referring to.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
shan-man
Offline
Joined: 2006-02-17
Points: 0

Hi!

> If you look into
> com.sun.java.swing.plaf.gtk.GTKPainter#paintTextAreaBa
> kground(), you see that this method ignores any
> colors set for the component. It simply calls
> engine.paintFlatBoxText() and that method sets the
> color only from its internal style. JTextField seems
> to have the same problem, btw.

Thanks for pointing this out everyone. I've filed bug #4893567 on this issue. It should be visible on the JDC shortly.

Thanks!
Shannon

sma
Offline
Joined: 2003-06-10
Points: 0

If you look into com.sun.java.swing.plaf.gtk.GTKPainter#paintTextAreaBackground(), you see that this method ignores any colors set for the component. It simply calls engine.paintFlatBoxText() and that method sets the color only from its internal style. JTextField seems to have the same problem, btw.

Stefan

dglasser
Offline
Joined: 2003-06-13
Points: 0

> If you look into
> com.sun.java.swing.plaf.gtk.GTKPainter#paintTextAreaBa
> kground(), you see that this method ignores any
> colors set for the component. It simply calls
> engine.paintFlatBoxText() and that method sets the
> color only from its internal style. JTextField seems
> to have the same problem, btw.

Thanks for the insight. This seems to violate the contract for the setBackground() method. I suspect that this LAF will have some more work done to it before 1.4.2_01 is released.

zander
Offline
Joined: 2003-06-13
Points: 0

I'm not familiar with the new Theme, but after seeing the JavaOne session, I can imagine bugs like this; its using a really screwed way of setting colors (indeed all things configurable)

But anyway; Why don't you use a html based JLabel?
Just put and around your text.

And use
for your linefeeds.

dglasser
Offline
Joined: 2003-06-13
Points: 0

> I'm not familiar with the new Theme, but after seeing
> the JavaOne session, I can imagine bugs like this;
> its using a really screwed way of setting colors
> (indeed all things configurable)
>
> But anyway; Why don't you use a html based JLabel?
> Just put and around your text.
>
And use
for your linefeeds.

That would work, but I'm not inclined to write a workaround for this one particular LAF, when every other one I've tried works fine--at least in this respect. Besides, my app lets the user change the LAF on the fly, like the SwingSet app. It's not like it's going to have the GTK hardcoded as the LAF. I think I'll just let it look like crap if the user installs and selects the GTK LAF. Then they'll select another one.

BTW, I say "installs" because GTK is not in the list returned by UIManager.getInstalledLookAndFeels() in 1.4.2. Maybe the Sun people know that it's not ready for primetime yet. In the case of my app, a user would have to be running 1.4.2 and explicitly enter "com.sun.java.swing.plaf.gtk.GTKLookAndFeel" into a dialog box for it to appear in the menu, so I don't think it's going to be a major problem.

zander
Offline
Joined: 2003-06-13
Points: 0

> > Why don't you use a html based JLabel?
> > Just put and around your text.

> That would work, but I'm not inclined to write a
> workaround for this one particular LAF, when every
> other one I've tried works fine

My point was that this seems to me to be the correct approuch to the first problem; so no workarounds are needed to begin with.

sma
Offline
Joined: 2003-06-10
Points: 0

The approach has the problem that you might get a different, probably wrong font then. It doesn't use the font set in your UI settings.

zander
Offline
Joined: 2003-06-13
Points: 0

> The approach has the problem that you might
> get a different, probably wrong font then.

In which Look and feel? Sounds like a bug.
It certainly works perfectly here.

> It
> doesn't use the font set in your UI settings.

I guess you are talking about Metal then, you have to set your font seperately for labels, yes. And as in default Metal the labels are [b]bold[/b], you are right. Most look and feels override that wierd defualt-setting, though.