<Swing Dev> Fake-Opaque Swing Components

Kirill Grouchnikov kirillcool at yahoo.com
Mon Nov 12 19:12:10 UTC 2007


Hi, Jasper

Wouldn't that conflict with the optimizations made in the rendering pipeline? The component is still declared as opaque, but does not effectively paint all the pixels in its bounds. So, potentially you can have overlapping components (by design or during layout transitions) which will be cut off in that area around the visual painting of the components. In addition, this approach (as well as the existing one) doesn't address watermarking functionality.

The issues with the performance can be addressed by repainting only the relevant area (such as caret does when it's blinking).

Thanks
Kirill

----- Original Message ----
From: Jasper Potts <Jasper.Potts at Sun.COM>
To: swing-dev at openjdk.java.net
Sent: Monday, November 12, 2007 10:53:41 AM
Subject: <Swing Dev> Fake-Opaque Swing Components

I have a problem with Nimbus that is common with other modern look and feels which we need to fix. The problem is how do setBackgound() and setForeground() map to how the component looks.
Because of the some components having rounded corners and all components having 2px spacing for painting the focus glow. You end up with this background area around the component (in red above). The area is not really of color Component.getBackgound() as that has another meaning which is the background of the actual component content such as the text field background(in green above).   


The obvious solution to the problem is to make the component non-opaque. Which means the red area would be transparent. The issue with this is it the performance for opaque components is much worse so for components like a text field which needs to be very responsive as you type this could be a issue.


Proposed Solution
So the proposed solution is for the component to be opaque and the outer background area to be painted as before but be the parent components getBackgound() color. This seems the right answer but means a change at a low level. So what I propose is adding a UIManager property to turn this on and changing the ComponentUI.update() method from:


public abstract class ComponentUI {
...
  public void update(Graphics g, JComponent c) {
	if (c.isOpaque()) {
	    g.setColor(c.getBackground());
	    g.fillRect(0, 0, c.getWidth(),c.getHeight());
	}
	paint(g, c);
  }
...
}


to:


public abstract class ComponentUI {
...
  public void update(Graphics g, JComponent c) {
	if (c.isOpaque()) {
            if (UIManager.getBoolean("Opaque.useParentBackgroundColor") && 
                c.getParent() != null){
                g.setColor(c.getParent().getBackground());
            } else {
	            g.setColor(c.getBackground());
            }
	    g.fillRect(0, 0, c.getWidth(),c.getHeight());
	}
	paint(g, c);
  }
...
}


I am open for better suggestions for the UIManager key name but that is the basic idea.


So what do you think??????


Thanks


Jasper







__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/swing-dev/attachments/20071112/58bb68f2/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: component-colors.png
Type: image/png
Size: 8446 bytes
Desc: not available
URL: <http://mail.openjdk.java.net/pipermail/swing-dev/attachments/20071112/58bb68f2/component-colors.png>


More information about the swing-dev mailing list