• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

paintComponent in JDesktopPane gives unexpected results when dragging

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ranchers,

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!

Thank you in advance for any help,
Steven
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Steven Rombauts
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much pete stein, that did the trick!!

Thank you for your time :-)
 
reply
    Bookmark Topic Watch Topic
  • New Topic