Re: Custom JPanel that clips children?



Arabella wrote:
I'm trying to implement a JPanel with rounded corners that clips it's children so they don't run outside the jpanel's (now rounded) corners.

I'm able to clip the JPanel, but the children keep painting outside the jpanel parent.

Do I have to override the paint routines of every child, or is there a way for a parent to clip children?

I tried overriding every paint method I could find, I even tried commenting out the contents of every paint, repaint, print, update, etc method and the child is still leaving artifacts outside the parent.

I'd expect paintChildren to work. You should be able to trace back where the child components are painted from. For instance using Thread.dumpStack(); is you are not using a debugger. You should be able to see what is happening in each method.


Some Swing painting erroneously uses setClip which will clear any user clipping region. It's difficult to get screen corruption without disabling double buffering, but it'll ignore your clipping region.

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
.



Relevant Pages

  • Re: Custom JPanel that clips children?
    ... Christian Kaufhold wrote: ... >> I'm trying to implement a JPanel with rounded corners that clips it's ... >> I'm able to clip the JPanel, but the children keep painting outside the ...
    (comp.lang.java.gui)
  • Custom JPanel that clips children?
    ... I'm trying to implement a JPanel with rounded corners that clips it's ... I'm able to clip the JPanel, but the children keep painting outside the ... I tried overriding every paint method I could find, ...
    (comp.lang.java.gui)
  • Re: Problems with painting of JPanel
    ... >I have a JPanel with a GridBagLayout. ... > which has a lot of custom paintig on it. ... > painting, without changing the painting and repaintig the whole JPanel ... http://uio.dev.java.net Unified I/O for Java ...
    (comp.lang.java.gui)
  • Problems with painting of JPanel
    ... I have a JPanel with a GridBagLayout. ... which has a lot of custom paintig on it. ... painting, without changing the painting and repaintig the whole JPanel ...
    (comp.lang.java.gui)
  • Re: CPaintDC class
    ... There may be some performance difference when you use the PAINTSTRUCT variable to clip painting yourself, but I have no information on that. ... However, by knowing update region beforehand, you can optimize your painting code a little bit by omitting the painting of unnecessary parts of client area. ...
    (microsoft.public.vc.language)