Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-07-2007, 02:19 AM
Member
 
Join Date: Jul 2007
Posts: 40
fernando is on a distinguished road
Help with drag from panel
Hi, I like this code for "DragPictureDemo", Drag and Drop and Data Transfer: Examples (The Java™ Tutorials > Creating a GUI with JFC/Swing > Drag and Drop and Data Transfer)

Web Demo: DragPictureDemo

My question is:
I have two panels, 1 on top, 1 at the bottom,
I need to drag and drop the images from the top to the bottom panel, do not allow to drag images from bottom to top, But the main image on the top panel is not removed (cannot cut), so all actions are "COPY" to bottom panel, no need to hold the CTL button.
I cannot get it to work.
Thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-07-2007, 07:57 AM
Member
 
Join Date: Jul 2007
Posts: 40
baltimore is on a distinguished road
Well actually, I found a solution to this already..

I make a Jlabel and add the mouse motion and drop listeners, then it the drop listener is fired and is found to be in a target (in this case another panel), I create a jlabel at runtime and place it in the other panel..

The only thing left is the ability for it to 'snap' into the the desired grid on the panel.. but I think i can manage that..
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-07-2007, 11:19 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,018
hardwired is on a distinguished road
Changes in PictureTransferHandler:
Code:
public int getSourceActions(JComponent c) { return COPY; }
Changes in DTPicture class:
Code:
public void mouseDragged(MouseEvent e) { //Don't bother to drag if the component displays no image. if (image == null) return; if (firstMouseEvent != null) { e.consume(); int action = TransferHandler.COPY; int dx = Math.abs(e.getX() - firstMouseEvent.getX()); int dy = Math.abs(e.getY() - firstMouseEvent.getY()); //Arbitrarily define a 5-pixel shift as the //official beginning of a drag. if (dx > 5 || dy > 5) { //This is a drag, not a click. JComponent c = (JComponent)e.getSource(); TransferHandler handler = c.getTransferHandler(); //Tell the transfer handler to initiate the drag. handler.exportAsDrag(c, firstMouseEvent, action); firstMouseEvent = null; } } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Control Panel not saving changes when I press OK RebelScum New To Java 0 03-21-2008 05:22 PM
Drag and drop abhivenugopal JavaServer Pages (JSP) and JSTL 0 01-30-2008 03:10 PM
Why the panel text changed? ottawalyli AWT / Swing 1 12-17-2007 06:56 AM
Why the panel text changed? ottawalyli SWT / JFace 0 12-16-2007 05:16 PM
How to place panel into frame vivek_9912 AWT / Swing 2 11-20-2007 12:21 AM


All times are GMT +3. The time now is 04:07 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org