File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Drawing rectangle with rubber band effect. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Drawing rectangle with rubber band effect." Watch "Drawing rectangle with rubber band effect." New topic

Drawing rectangle with rubber band effect.

geeta khurana

Joined: May 18, 2001
Posts: 6
I am trying to draw a rectangle with rubber band effect on a swing JComponent. If I draw the rectangle in the mousedragged event of the component, it draws the rectangle with flickering effect. Also, if I include the code in the paint method and call the paint() method through update(), it doesn't go to the paint method at all. I use the paint method for painting a selected component. In the later case, I have used the example to draw the rectangle from Java help. I am enclosing the code here with. Pls help me out. I know, its tedious to go through the code but pls help.

The second approach

Please use the [ code ] opening and closing tags (without the spaces) when posting source code. I edited the msg for now.
Thanks for your cooperation.
- satya

[This message has been edited by Madhav Lakkapragada (edited July 09, 2001).]
Amit Agarwal
Ranch Hand

Joined: May 09, 2001
Posts: 92
Hi geeta,
you need to use double buffering of the JPanel to get flicker-free drawing. use either JPanel.setDoubleBuffered(true); or simply pass a boolean - true - in the call to the super() in the constructor. i.e.

I agree. Here's the link:
subject: Drawing rectangle with rubber band effect.
It's not a secret anymore!