<Swing Dev> Painting a JComponent without clipping children
Alexander.Potochkin at oracle.com
Mon Jun 6 05:02:04 PDT 2011
> Thanks, I will look at this, it looks interesting. In fact, the reason why I want to avoid setting the clip is because I'm using swing to draw gui components in Java according to a standard called ARINC 661 where some of the components are just containers with no size but just an offset position, where the children can even have a negative position relative to their parent container.
Did you try to resize you container before painting?
I am thinking about having a big main container which contains all your
children with negative position
so the applied clip wouldn't hurt you
If you control the painting hierarchy you can also try overriding
paint() method of every child component
and reset clip there
However may the hack you found is only way to make what you need
> Sent from my iPad
> On 3 juin 2011, at 16:13, Alexander Potochkin<Alexander.Potochkin at oracle.com> wrote:
>> Hello Herve
>> I don't really get it why you need to avoid setting the clip,
>> but anyway the following may be interesting to you
>> Piet is transforming Swing components using JXLayer component
>>> (reposted from awt-dev list, I picked up the wrong list before)
>>> I'm new to this mailing list and I'm not *really* asking how to do it because I know how it's possible to do it by using a hack (mainly getting and setting the BUFFER and TILE parts of the "flags" field for the JComponent by reflection, and "rewriting" the paintChildren method without the clipping part). I'm using it in the http://sourceforge.net/projects/j661/ project to be able to use custom Swing containers which only offset the position or transform their children graphic context, without clipping them (allowing to use negative positions for the children widgets, for example).
>>> I'm asking if there is a way to do this without playing with the private "flags" field, because I need to be able to do the same thing in a restricted JNLP environment. I know a "regular"' way to do this, but it would be a little cumbersome (offsetting the positions of all children widgets in the parent container, to be sure that the positions of the children are never negative, for example). But it's not very good for performance when something change in the parent container....
>>> There are many projects which either play with this private field, or use transforms, but in this later case they still apply a clipping. Is it possible to play with the Graphics2D clippings for example before using the JComponent paintChildren method - or would this approach work ? Or would the only way to do it without compromising Security be to have a way to get / set the TILE and BUFFER value of the "flags" field without reflection ?
>>> Thanks by advance if you have ideas about this, and sorry if this prose is not crystal clear ;)
More information about the swing-dev