I need to draw a line between two JInternalFrames in a JDesktopPane.
I have created a subclass of JDesktopPane and added my line drawing into the paintComponent() method. The line is drawn, but when I am dragging the frames around, I get some very weird behaviour. Please look at the following two little screenshots:
This is with the desktoppane's dragMode set to LIVE_DRAG_MODE :
and this is with the dragMode OUTLINE_DRAG_MODE:
As soon as I release the frame I am dragging around, and resize the window, the line gets drawn correctly. I tried adding a swing Timer to call repaint() on the desktoppane more frequently, but this still gave me some weird results during dragging (although the correct line will now be drawn as soon as I release one of the frames)
Here is a quick sample code which should compile and give you an idea of my problem :
I put a gradient background color in there just to see how that responds to the dragging but this seems to be drawn very nicely during the frame dragging.
I am hoping someone might have some tips as to why I am having this problem.
It's not such a big deal but it looks so very ugly!
Your problem is that the JDesktopPane is not painting itself after the internal frames are moved. You can solve this by adding a ComponentListener to the JInternalFrames and calling repaint() on the JDesktopPane in the componentMoved method, like so:
You will need to decide what to do when/if your internal frames are iconified or removed, and may also need to use an InteralFrameListener as well.
Joined: Apr 21, 2009
Thank you very much pete stein, that did the trick!!
Thank you for your time :-)
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: paintComponent in JDesktopPane gives unexpected results when dragging