List Info

Thread: JXPanel and Translucency




JXPanel and Translucency
user name
2006-08-25 20:15:30
We had an internal review today that covered the JXPanel and
ran into some issues with regards to translucency.

Currently, there is an "alpha" property on the
JXPanel which you can use to specify how translucent the
panel and its contents should be. The "paint"
method of JXPanel sets an AlphaComposite on the Graphics
used for painting, causing JXPanel and all components on it
to be translucent.

However, what happens if a child component is painted?
Normally, that paint request only goes up the tree if the
child component is not opaque, otherwise only the child
component is painted. However, since JXPanel needs to set
the AlphaComposite, it is necessary that painting start at
the JXPanel, not at the child component.

The current solution is to install a custom repaint manager.
The repaint manager walks up the containment heirarchy
looking for a JXPanel that is translucent. If there is one,
painting starts from there.

The obvious problem with this hack is that we replace the
repaint manager (behind the scenes!). Eek.

There is another solution. If I had a visible, non-opaque,
fully transparent component on top of all the components on
the JXPanel (think: glasspane), then painting is forced to
happen starting from the JXPanel (remember: walk up the tree
if non-opaque. And, since the component covers the whole
area, it causes painting to start at the top -- the JXPanel
the "glasspane" is covering).

For this solution to work, the JXPanel would need to have a
JLayeredPane within it. That layered pane would have a
content pane and a transparent visible helper pane. Just
like with JFrame, we could automatically route add/remove
calls to the content pane. So, API wise, you'd still use it
the same as before.

Almost.

The problem is that now, in any code walking the containment
heirarchy, you will be 2 levels removed. That is, before it
was JXPanel->JTextField, but now it would be
JXPanel->JLayeredPane->Content Pane->JTextField.

For this reason, it was proposed to split the translucency
functionality out of JXPanel into
JXTranslucentPanel/JXLayeredPanel which would then extend
JXPanel.

What do y'all think of this?

There is an additional benefit for having a JXLayeredPanel
--> you could use it to achieve mini glass pane effects.
That is, instead of having to use the frame level glass pane
and translate to a per component basis, you could paint on
the component itself. For some effects, this could be nice.


Richard
[Message sent by forum member 'rbair' (rbair)]

http://forums.java.net/jive/thread.jspa?messageID=147243


------------------------------------------------------------
---------
To unsubscribe, e-mail: jdnc-unsubscribejdnc.dev.java.net
For additional commands, e-mail: jdnc-helpjdnc.dev.java.net

JXPanel and Translucency
user name
2006-08-25 23:31:37
What does a "mini-" JXLayeredPane buy you that
you don't get with the existing JLayeredPane?  Or is it
just a solution in search of more raison d'etre?
[Message sent by forum member 'twalljava' (twalljava)]

http://forums.java.net/jive/thread.jspa?messageID=147312


------------------------------------------------------------
---------
To unsubscribe, e-mail: jdnc-unsubscribejdnc.dev.java.net
For additional commands, e-mail: jdnc-helpjdnc.dev.java.net

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )