Hi Kirill,

Kirill Grouchnikov wrote:
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.

Jasper's proposal WILL paint all pixels in its bounds. It simply mentions painting the outer edges in the parent background color.


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

Of course. Swing already tries to constrain the areas that it repaints. What Jasper refers to is the performance hit we'll take (although it's not quantified how much...Jasper?) by forcing painting to start at a higher level.

Thanks!
Shannon


Thanks
Kirill

----- Original Message ----
From: Jasper Potts <[EMAIL PROTECTED]>
To: swing-dev@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.

*P**roposed 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



--
Shannon Hickey
[EMAIL PROTECTED]
Swing Team - Sun Microsystems, Inc.
http://java.sun.com/javase/technologies/desktop

Reply via email to