[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Drag and Drop- showing image when dragging

Posted on 2001-07-31
9
Medium Priority
?
618 Views
Last Modified: 2006-11-17
how do i show a custom image when i am dragging??

heres is a sample of my code
public class CurrentObjectsLabel extends JLabel
    implements DragSourceListener, DragGestureListener    {

  DragSource dragSource = null;
  java.awt.Image image2 = null;
 
  public CurrentObjectsLabel(String name,Icon image,int value) {
    super(name,image,value);
    dragSource = new DragSource();
    dragSource.createDefaultDragGestureRecognizer( this, DnDConstants.ACTION_MOVE, this);
    loadImage();
  }

  public void dragGestureRecognized( DragGestureEvent event) {
       String name = getText();
     System.out.println("Moving oject "+name);
     StringSelection text = new StringSelection(name);
     Point p = new Point(0,0);
        dragSource.startDrag (event,DragSource.DefaultMoveDrop,image2,p,text, this);
  }

 i havent tried using the dragSource.createDefaultDragGestureRecongizer(java.awt.dnd.peer.DragSourceContextPeer dscp, DragGestureEvent dgl, Cursor dragCursor, Image dragImage, Point imageOffset, Transferable t, DragSourceListener dsl)

method because im new to the whole DnD package and wouldnt know where to start for creating a DragSourceContextPeer!!

if anyone can show me some code as to how its done it would be a great help!!
thanks in advance!!

J.B
0
Comment
Question by:j_baxter99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 92

Expert Comment

by:objects
ID: 6337114
If your target environment is Windows then unfortunately I don't think you can.
0
 
LVL 92

Expert Comment

by:objects
ID: 6337130
What your doing looks correct (specifying the image in startDrag) so I'm guessing your on a Windows platform.

The problem is apparently caused by MS.

0
 
LVL 15

Expert Comment

by:ozymandias
ID: 6337333
You just specify an Icon in the startDrag method.
Here is the code :

public void dragGestureRecognized(DragGestureEvent dge){
    ImageIcon icon = new ImageIcon("custom.gif");
    Toolkit tk = this.getToolkit();
    Cursor cursor = tk.createCustomCursor(icon.getImage(), new Point(0,0), "cursor");
    dragSource.startDrag(dge, cursor, ti, this);
}

You just need to specify the image you want to use in :

    ImageIcon icon = new ImageIcon("custom.gif");

instead of "custom.gif

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 15

Expert Comment

by:ozymandias
ID: 6337336
NB : you can use any string instead of "cursor".
The Point is the hotspot of the cursor, i.e. the active bit of the cursor.
0
 
LVL 15

Accepted Solution

by:
ozymandias earned 300 total points
ID: 6337346
Sorry I should have said you specify a cursor, not an icon.

In the startDrag method the DragSource.DefaultMoveDrop object is the cursor that will be used and it is the default drag cursor for the platform. You can replace it with any cursor of your choice.
0
 

Author Comment

by:j_baxter99
ID: 6339514
pretty **** that you cant do it on windows!!!

cheers lads!
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 6339567
You can do it on windows.
The code I posted works fine on windows.
Or at least it works fine on my Windows machine which is NT4.
0
 
LVL 92

Expert Comment

by:objects
ID: 6339589
Cursors work, drag images don't.
0
 

Author Comment

by:j_baxter99
ID: 6343728
sorry , i meant the images on windows!(not cursor)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question