5

I'm making a component (extending JComponent) which will have some decoration drawn over the top of it and partly outside its bounds.

I would like to know if there's a way of drawing outside the component using self-contained code (I don't want to have to do any drawing in the parent container, for example).

Tharwen
  • 3,057
  • 2
  • 24
  • 36

1 Answers1

2

AFAIK, there is no easy solution. One way to achieve this is to draw on the container's GlassPane, as shown here. IMHO, I would just modify the Graphics object of the component to change the "apparent" bounds, which will enable you to draw stuff that's "outside the bounds" on the component itself.

Community
  • 1
  • 1
mre
  • 43,520
  • 33
  • 120
  • 170
  • 1
    You mean with setClip? I thought that could only be used to shrink the drawing area. – Tharwen Nov 01 '11 at 19:25
  • 2
    OK, I was wrong. The reason I've only just marked this as the answer is that I've just fixed a problem that I've been stuck on for hours which has a really simple solution: **If you don't repaint the parent container as well as the component, no rendering will show up on it.** Obvious, but not easy to spot because I was redrawing in mouse and component events, some of which repaint the container and some of which don't. – Tharwen Nov 03 '11 at 01:00
  • @Tharwen, Then you should answer your own question and mark that as the correct one. :D – mre Nov 03 '11 at 13:01
  • No, your answer was the solution, but that bold part was just a thing that I thought would be helpful for anyone reading this later. – Tharwen Nov 10 '11 at 11:28