Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Dragging an image beyond the JFrame limits  RSS feed

 
Gary W. Lucas
Ranch Hand
Posts: 65
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a bit stuck here and was wondering if anyone could get me started in the right direction. I'm trying to figure out how to drag an image beyond the JFrame limits.

In Netbeans, when you drag a Java file editor pane out of the main application frame and onto a second monitor, Netbeans provides a semi-transparent image of the pane you're dragging. I would like to reproduce this effect in my own code. I've been able to do this in a test program (code below) using a glass pane, but cannot figure out a good way to get the image to drag beyond the limits of the main application frame. I looked at the DragnGhostDemo from SwingHacks but it has the same limitation.

Does anyone have suggestions on how this could be accomplished?

Thanks in advance.

Gary



In the test application below, click on on the button and drag it's image across the application frame.

 
Gary W. Lucas
Ranch Hand
Posts: 65
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since yesterday, I found one solution to this problem but it doesn't quite work.

The solution I tried was to create a JFrame to place over the entire screen and operate on it's glass pane. When the user presses the button, I perform the following



This does allow me to drag the image beyond the limits of the original application frame. The problem is that the image doesn't keep up with the mouse pointer, but lags behind slightly (and catches up when the user stops moving the mouse). This behavior is not terrible, but it's not wonderful either. Netbeans does not seem to have the same problem, so there must be a better way of doing this.

I've done a couple obvious things, but they don't seem to help. On the theory that the repaint was slow because it was repainting the entire display area, I changed the repaint() call in the mouse-drag routine to pass in a minimal bounds. I also modified the TestIcon class to create a permanent image for the icon so that it wouldn't have to draw it up from scratch every time it was painted.

If anyone has further suggestions, I'd welcome your comments.

Gary
 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know precious little about dragging, but there is a drag'n'drop API: start here. If that is completely unrelated to your problem, sorry.
 
Gary W. Lucas
Ranch Hand
Posts: 65
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell,

Thanks for your reply. It did turn out to be helpful in an indirect way. I wasn't really trying to perform a Drag-n-Drop so much as I was trying to use a mouse drag operation as a way of identifying a place to create a new window on the display. Same gestures, different operation...

Anyway, thinking about your DragNDrop lead me to realize that I could accomplish what I was trying to do in a vastly simpler manner just by creating a custom cursor.... Doh!

Gary



Incidentally, I've started working on some code using DragNDrop and I must say that I sympathize with your comment that you know "precious little" about it. Whoever designed that API was in love with complexity and fussy little nuances that make it hard to figure out how to use it.
 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I even copied a lot of the examples from that Java Tutorials section and they wouldn't work. That was ages ago.

And “you're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!