The call to super.paint(g) should cause the Rectangle to be painted over when the Container paints its child components (as advertised: see paint method in JComponent api Method Detail). If you want the rectangle to persist, you could draw it after the call to super.paint. The paint method will draw on top of its parent (enclosing class) container and all of the child components.
If not drawing on top of child components of a Container, other options include:
1 — set a border on the selected component, eg
2 — you could override the paintComponent method, get the bounds of the selected component and use it to draw your rectangle around the component.
About manipulating variables inside your paint code from within your event code: yes, this is considered good practice. You can use booleans, int flags, null state and the like. The paint code should be concerned only with rendering your graphics/images. The event code is where you control what goes on in the paint code. [ November 15, 2004: Message edited by: Craig Wood ]
Joined: Sep 06, 2004
thanks! I just got it when i was driving. Just call it after the drawing. OHh man!