How to drag image in left panel then drop into right panel??

Dear friends.
I have following code, it is runnable, just add two jpg image files is ok, to run.
I tried few days to drag image from left panel then drop into right panel or vice versa, but not success, can any GUI guru help??
Thanks.
Sunny
[1]. main code/calling code:
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class ImagePanelCall extends JComponent {
     public  JSplitPane ImagePanelCall() {
          setPreferredSize(new Dimension(1200,300));
          JSplitPane          sp = new JSplitPane();
          sp.setPreferredSize(new Dimension(1200,600));
          sp.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
          add(sp);
          ImagePanel     ip = new ImagePanel();
          ImagePanel     ip1 = new ImagePanel();
          ip.setPreferredSize(new Dimension(600,300));
          ip1.setPreferredSize(new Dimension(600,300));
          sp.setLeftComponent(ip);// add left part
          sp.setRightComponent(ip1);// add right part
          sp.setVisible(true);
          return sp;
     public static void main(String[] args) {
          JFrame frame = new JFrame("Test transformable images");
          ImagePanelCall  ic = new ImagePanelCall();
          frame.setPreferredSize(new Dimension(1200,600));
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.getContentPane().add(ic.ImagePanelCall(), BorderLayout.CENTER);
          frame.pack();
          frame.setVisible(true);
}[2]. code 2
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class ImagePanel extends JComponent {
     private static final Cursor DEFAULT_CURSOR = new Cursor(Cursor.DEFAULT_CURSOR);
     private static final Cursor MOVE_CURSOR = new Cursor(Cursor.MOVE_CURSOR);
     private static final Cursor VERTICAL_RESIZE_CURSOR = new Cursor(Cursor.N_RESIZE_CURSOR);
     private static final Cursor HORIZONTAL_RESIZE_CURSOR = new Cursor(Cursor.W_RESIZE_CURSOR);
     private static final Cursor NW_SE_RESIZE_CURSOR = new Cursor(Cursor.NW_RESIZE_CURSOR);
     private static final Cursor NE_SW_RESIZE_CURSOR = new Cursor(Cursor.NE_RESIZE_CURSOR);
     public Vector images;
     * Create an ImagePanel with two images in.
     * A MouseHandler instance is added as mouse listener and mouse motion listener.
     public ImagePanel() {
          images = new Vector();
          images.add(new TransformableImage("swing/dnd/Bird.gif"));
          images.add(new TransformableImage("swing/dnd/Cat.gif"));
          setPreferredSize(new Dimension(600,600));
          MouseHandler mh = new MouseHandler();
          addMouseListener(mh);
          addMouseMotionListener(mh);
     * Simply paint all the images contained in the Vector images, calling their method draw(Graphics2D, ImageObserver).
     public void paintComponent(Graphics g) {
          Graphics2D g2D = (Graphics2D)g;
          for (int i = images.size()-1; i>=0; i--) {     
               ((TransformableImage)images.get(i)).draw(g2D, this);
     * Inner class defining the behavior of the mouse.
     final class MouseHandler extends MouseInputAdapter {
          private TransformableImage draggedImage;
          private int transformation;
          private int dx, dy;
          public void mouseMoved(MouseEvent e) {
               Point p = e.getPoint();
               TransformableImage image = getImageAt(p);
               if (image != null) {
                    transformation = image.getTransformation(p);
                    setConvenientCursor(transformation);
               else {
                    setConvenientCursor(-1);
          public void mousePressed(MouseEvent e) {
               Point p = e.getPoint();
               draggedImage = getImageAt(p);
               if (draggedImage!=null) {
                    dx = p.x-draggedImage.x;
                    dy = p.y-draggedImage.y;
          public void mouseDragged(MouseEvent e) {
               if (draggedImage==null) {
                    return;
               Point p = e.getPoint();
               repaint(draggedImage.x,draggedImage.y,draggedImage.width+1,draggedImage.height+1);
               draggedImage.transform(p, transformation,dx,dy);
               repaint(draggedImage.x,draggedImage.y,draggedImage.width+1,draggedImage.height+1);
          public void mouseReleased(MouseEvent e) {
               Point p = e.getPoint();
               draggedImage = null;
     * Utility method used to get the image located at a Point p.
     * Returns null if there is no image at this point.
     private final TransformableImage getImageAt(Point p) {
          TransformableImage image = null;
          for (int i = 0, n = images.size(); i<n; i++) {     
               image = (TransformableImage)images.get(i);
               if (image.contains(p)) {
                    return(image);
          return(null);
     * Sets the convenient cursor according the the transformation (i.e. the position of the mouse over the image).
     private final void setConvenientCursor(int transfo) {
          Cursor currentCursor = getCursor();
          Cursor newCursor = null;
          switch (transfo) {
               case TransformableImage.MOVE : newCursor = MOVE_CURSOR;
                    break;
               case TransformableImage.RESIZE_TOP : newCursor = VERTICAL_RESIZE_CURSOR;
                    break;
               case TransformableImage.RESIZE_BOTTOM : newCursor = VERTICAL_RESIZE_CURSOR;
                    break;
               case TransformableImage.RESIZE_LEFT : newCursor = HORIZONTAL_RESIZE_CURSOR;
                    break;
               case TransformableImage.RESIZE_RIGHT : newCursor = HORIZONTAL_RESIZE_CURSOR;
                    break;
               case TransformableImage.RESIZE_TOP_LEFT_CORNER : newCursor = NW_SE_RESIZE_CURSOR;
                    break;
               case TransformableImage.RESIZE_TOP_RIGHT_CORNER : newCursor = NE_SW_RESIZE_CURSOR;
                    break;
               case TransformableImage.RESIZE_BOTTOM_LEFT_CORNER : newCursor = NE_SW_RESIZE_CURSOR;
                    break;
               case TransformableImage.RESIZE_BOTTOM_RIGHT_CORNER : newCursor = NW_SE_RESIZE_CURSOR;
                    break;
               default : newCursor = DEFAULT_CURSOR;
          if (newCursor != null && currentCursor != newCursor) {
               setCursor(newCursor);
     public static void main(String[] args) {
          JFrame frame = new JFrame("Test transformable images");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.getContentPane().add(new ImagePanel(), BorderLayout.CENTER);
          frame.pack();
          frame.setVisible(true);
}[3]. code 3
import java.awt.*;
import javax.swing.*;
import java.awt.image.*;
public final class TransformableImage extends Rectangle {
     public static final int MOVE = 0;
     public static final int RESIZE_TOP = 10;
     public static final int RESIZE_BOTTOM = 20;
     public static final int RESIZE_RIGHT = 1;
     public static final int RESIZE_LEFT = 2;
     public static final int RESIZE_TOP_RIGHT_CORNER = 11;
     public static final int RESIZE_TOP_LEFT_CORNER = 12;
     public static final int RESIZE_BOTTOM_RIGHT_CORNER = 21;
     public static final int RESIZE_BOTTOM_LEFT_CORNER = 22;
     public static final int BORDER_THICKNESS = 5;
     public static final int MIN_THICKNESS = BORDER_THICKNESS*2;
     private static final Color borderColor = Color.black;
     private Image image;
     * Create an TransformableImage from the image file filename.
     * The TransformableImage bounds (inherited from the class Rectangle) are setted to the corresponding values.
     public TransformableImage(String filename) {
          ImageIcon ic = new ImageIcon(filename);
          image = ic.getImage();
          setBounds(0,0,ic.getIconWidth(), ic.getIconHeight());
     * Draw the image rescaled to fit the bounds.
     * A black rectangle is drawn around the image.
     public final void draw(Graphics2D g, ImageObserver observer) {
          Color oldColor = g.getColor();
          g.setColor(borderColor);
          g.drawImage(image, x, y, width, height, observer);
          g.draw(this);
          g.setColor(oldColor);
     * Return an int corresponding to the transformation available according to the mouse location on the image.
     * If the point p is in the border, with a thickness of BORDER_THICKNESS, around the image, the corresponding
     * transformation is returned (RESIZE_TOP, ..., RESIZE_BOTTOM_LEFT_CORNER).
     * If the point p is located in the center of the image (i.e. out of the border), the MOVE transformation is returned.
     * We allways suppose that p is contained in the image bounds.
     public final int getTransformation(Point p) {
          int px = p.x;
          int py = p.y;
          int transformation = 0;
          if (py<(y+BORDER_THICKNESS)) {
               transformation += RESIZE_TOP;
          else
          if (py>(y+height-BORDER_THICKNESS-1)) {
               transformation += RESIZE_BOTTOM;
          if (px<(x+BORDER_THICKNESS)) {
               transformation += RESIZE_LEFT;
          else
          if (px>(x+width-BORDER_THICKNESS-1)) {
               transformation += RESIZE_RIGHT;
          return(transformation);
     * Move the left side of the image, verifying that the width is > to the MIN_THICKNESS.
     public final void moveX1(int px) {
          int x1 = x+width;
          if (px>x1-MIN_THICKNESS) {
               x = x1-MIN_THICKNESS;
               width = MIN_THICKNESS;
          else {
               width += (x-px);
               x = px;               
     * Move the right side of the image, verifying that the width is > to the MIN_THICKNESS.
     public final void moveX2(int px) {
          width = px-x;
          if (width<MIN_THICKNESS) {
               width = MIN_THICKNESS;
     * Move the top side of the image, verifying that the height is > to the MIN_THICKNESS.
     public final void moveY1(int py) {
          int y1 = y+height;
          if (py>y1-MIN_THICKNESS) {
               y = y1-MIN_THICKNESS;
               height = MIN_THICKNESS;
          else {
               height += (y-py);
               y = py;               
     * Move the bottom side of the image, verifying that the height is > to the MIN_THICKNESS.
     public final void moveY2(int py) {
          height = py-y;
          if (height<MIN_THICKNESS) {
               height = MIN_THICKNESS;
     * Apply a given transformation with the given Point to the image.
     * The shift values dx and dy are needed for move tho locate the image at the same relative position from the cursor (p).
     public final void transform(Point p, int transformationType, int dx, int dy) {
          int px = p.x;
          int py = p.y;
          switch (transformationType) {
               case MOVE : x = px-dx; y = py-dy;
                    break;
               case RESIZE_TOP : moveY1(py);
                    break;
               case RESIZE_BOTTOM : moveY2(py);
                    break;
               case RESIZE_LEFT : moveX1(px);
                    break;
               case RESIZE_RIGHT : moveX2(px);
                    break;
               case RESIZE_TOP_LEFT_CORNER : moveX1(px);moveY1(py);
                    break;
               case RESIZE_TOP_RIGHT_CORNER : moveX2(px);moveY1(py);
                    break;
               case RESIZE_BOTTOM_LEFT_CORNER : moveX1(px);moveY2(py);
                    break;
               case RESIZE_BOTTOM_RIGHT_CORNER : moveX2(px);moveY2(py);
                    break;
               default :
}

I gave you a simple solution in your other posting. You never responded to the suggestion stating why the given solution wouldn't work, so it can't be that urgent.

Similar Messages

  • My drag images disappear when they are dropped on a correct drop target during the drag and drop interaction.

    What am I missing. The opacity is at 100%. The drop target is a highlighted box from objects. I am using Captivate 8.

    Hi there,
    You might want to make sure your Depth setting is not set to Back instead of Front on your drop target(s).
    The Depth setting is accessed via the Drag and Drop window/panel under Format setting while you have your drop target selected.
    If your Depth setting is set to Back, especially if your opacity is set to 100% on your highlight box/drop target, your drag image would go behind your drop target giving the effect of disappearing behind your highlight box - especially if the drop target is larger than the drag image.

  • How to view images full size and then import selected ones to macbook

    I want to view my images stored on external drive full size and download selected to MacBook pro

    Use a photo viewer like Preview (this has nothing to do with iPhoto)
    LN

  • How to drag sections/pages from separate Pages document into current document using Pages 5

    I want to clarify whether or not Pages 5 allows users to drag individual pages and/or sections from separate Pages documents into the user's current working document. This feature was available in Pages 4 but seems to have been eliminated in the upgraded version.

    You can take this to be the answer for most things Pages 5…
    … No!
    Use Pages '09 instead.
    Peter

  • How to insert image file as a field value into blob field type using insert statment

    i have a column named picture of datatype BLOB
    now i want to insert an image file into that column using
    INSERT state so that it can be called in a jsp file using
    getBLOB request method.
    HELP!!
    thank you
    sal

    See this link
    http://www.psoug.org/reference/dbms_lob.html

  • How do I rotate a PDF that I dropped into a Pages document?

    I got a PDF off the internet that is just what I need. But it is orientated incorrectly. So, how do I rotate it in my Pages document?
    OR, if this is not possible, how can I rotate individual lines of text within my Pages document so that the correspond with the PDF?
    Can I do this simply by using the Pages toolbar? I honestly don't know that I am capable of downloading a program off the internet, as I have tried this before for other things and the process has always gone +very awry+. Any SIMPLE solutions would be appreciated, as I am very challenged when it comes to using computers.
    Thank you

    Hi Tom,
    Some late comments that may help.
    I went to the link in your post and opened the pdf file in Safari. Judging by the icons for the available controls, Safari was using the Adobe Reader plug in, which does will display thumbnails of the original pages, but will not allow you to select or copy a single page.
    I went File > Save as, and saved the pdf file to the desktop, then opened the file using Preview (control click or right click the file icon and choose Open with > Preview.
    Preview displays the page thumbnails by default, allows you to select a single page by clicking its thumbnail, and allows you to Copy that selected page.
    Which is what I then did.
    I scrolled to Page 16, clicked on the thumbnail to select it, pressed command-C to copy.
    I then went to Pages, where I had already created a new document from one of the Blank word processor templates.
    I clicked in the document, then pressed command-V to paste the copied page into the document. It pasted (as expected) as an Inline object, so I went to the Format bar (above the page) and clicked Floating to change the pasted (and still selected) drawing to a Floating object.
    Then I opened the Inspector and chose the Metrics Inspector (ruler icon).
    At the bottom of the Inspector window, I changed the 0 in the Rotate Angle box to -90, then pressed tab to effect the change.
    In the Size section, I checked that the Constrain Proportions box was checked, then used the stepper controls on one of the Size boxes to resize the drawing to fit the width of the page. As the proportions were constrained, this also adjusted the height of the drawing. While adjusting the size, I also used the steppers of the X and Y position boxes to position the drawing where I wanted it.
    Finally, to ensure that text did not slip under (or over the face of) the drawing, I switched to the Wrap inspector and selected one of the Wrap buttons.
    The keys here are to make sure the object remains selected through the whole process (or is re-selected if it becomes unselected), and to make sure you are working with a Floating object (the drawing) rather than an Inline object.
    Regards,
    Barry

  • How to add image to webdynpro screen . ?

    How to add image to webdynpro screen . ?

    hi,
    right click ur application and then click on create mime object.
    with Mime Objects u cn upload doc , jpeg, or giff files from our local system into the webdypnpro system .
    You can even try creating the MIME objects in webdynrpo abap .
    Right click on ur component->mime object->import
    after importing you can see that image into your component as MIME object .Now insert a UI element image into your view layout .
    Go to the source property of IMAGE element and select F4 option , u will find a window is opening with some tabs
    Select tab COMPONENT IMAGES and component name select your component .
    You will find the image which you have imported into this section just select the image and save it.
    In the transaction sicf/bc/webdynpro , u cn check your component name there you can view the mime objects created by you .
    also refer the SAP online help :
    http://help.sap.com/saphelp_crm50/helpdata/en/46/bb182fab4811d4968100a0c94260a5/content.htm
    to knw more abt mime repositories.
    http://help.sap.com/saphelp_nw04/helpdata/en/f3/1a61a9dc7f2e4199458e964e76b4ba/content.htm
    regards,
    Amit

  • Why can't I drag images directly onto illustrator ?

    When I search google images in Safari or Google Chrome,
    the browsers allow me to drag images directly into AI (Adobe Illustrator) or PS. I'm unable to do this in Firefox, I have to drag images onto my desktop then into AI or PS.

    Hi All,
    This bug has been fixed in the latest version of Dreamweaver CC 2014, which is now available for download.
    Download it from https://creative.adobe.com/ or directly through the Creative Cloud desktop app.
    We’re excited to hear back from you. Please share your feedback.

  • How to drag and drop images on html page?

    Is there a simple way to drag images on your webpage so that they are positioned at different coordinates?
    I have an img whose CSS position is set to absolute and top and left are both set to zero. I would like to simply drag the image to another location in the design view and have it update the tag's style with the new coordinates.
    The types of web pages I am building must use abosolute positioning extensively and having to hand code each position would be very inefficient.
    Thanks!

    If you are using CC then you can't;  If you are using CS6 then:
    Insert >> Layout Objects >> ApDiv
    See this picture:
    Once the APDIV is inserted, you can drag it whereever you it to be.
    Good luck.

  • Can't drag image from browser into Artwork panel

    Hey all,
    This is on Snow Leopard, using the latest iTunes and Firefox versions.
    When a file (or group of files) lacks artwork, I often use Google Images, find the appropriate image, drag the image to the desktop, then drag the image from the desktop into the mp3 file's "Artwork" panel when you have "Get Info" opened--and then delete the file on the desktop. There's too many steps.
    Is there however some way to directly drag the image from Firefox directly into iTunes? And if not, is there some other easier way to add artwork?
    Thank you for any tips.

    Jolly Giant wrote:
    you can add artwork by going these routes:
    select them all in iTunes, +get info+, copy the image out of e.g. Safari or Preview, click once into the artwork box and paste the image into it.
    Oh! I like this method. Saves the step of having to place it somewhere on the hard drive and deleting it after. Thank you, Jolly Giant.

  • CS5 - how to drag in images from a browser easily?

    In previous version (on the PC anyway) you caould literally drag an imaeg from a web browser right into a blank spot in photoshop and it would immedietly become available to work on. 
    This saved me tons of time (right click imaeg, save to desktop, go to photoshop, open, select image, etc) ...was all done instantly.
    With just a little experience using CS5 under my belt, it seems as if I can't get this to work anymore.  Perhaps it's my ignorance with the MAC OS (I'm new to it), or I need a different browser, etc.
    Anyone know how to drag and drop images from the web (browser), directly into Photoshop (CS5)? I'm using a new MacBook Pro 13"

    I see.  I am used to doing that, then moving the image up into the workspace and dropping it.  This is actually a small step easier... and it worked!
    Thanks for the tip.

  • How to drag an image around?

    hi,
    does anyone knows how to drag a image (.gif or .jpg picture) around inside a scrollPane?
    i have tried to drag shapes (like rectangle) around and it works fine but not for a .gif picture,
    so does anyone have any idea how to do so??
    Thanks!!!!!

    Hi,
    You could solve it like this.
    Draw the image on for example a (J)Component So make sure the component is of exact size as the image.
    Add this component to some container (which uses a null layout), set the location of the component.
    Then add a MouseMotionListener to this component and listen for the the events. This way by using the method: setLocation(Point x) on the component you can move the component around, so the image on the component can be moved.
    I hope this helps you out.

  • How Do You Turn On http Address in Comments of dragged image files?

    Greetings:
    In the "old days" when I dragged an image from Safari to the desktop, the image retained its original web address in comments. Since Panther I lost this ability, and even with 10.4.11 the comments or Spotlight box is blank regarding dragged image files. If the feature's there how do i turn it on??
    Thanks,
    James Greenidge

    The icon you see is telling your to connect the iPad to iTunes on the computer. You have to activate it via the computer before you can use it.
    Depending up on the setting, if iTunes is installed on the computer, iTunes may automatically open when the iPad is connected. If iTunes doe not automatically open, then open it. The iPad should be displaying the icon when you connect it to your computer.

  • In the slide show view how can you pin the "next" Arrow to the ultimate edge so it is in the same place as the full screen image, it will pin to the left edge but not the right.

    In the slide show view how can you pin the "next" Arrow to the ultimate edge so it is in the same place as the full screen image, it will pin to the left edge but not the right.

    Hello,
    Please make sure that the next button is pinned to the right side as there in the attached image.
    If it is already pinned, you can try removing any embedded HTML code and checking it.
    Regards,
    Neha

  • How to open a pdf file and then attach it with images

    I am new to Indesign Server.
    I'm currently working on a pdf.
    I have a white blank pdf template.
    that I want to attach/glue it with images.
    How to open a pdf file and then attach it with images.
    Please, help me.
    Thanks.

    First step would be to make yourself familiar with InDesign desktop version.
    Whatever you intend to achieve, do it there manually. (see regular app docs or forums)
    Then try to automate your steps with scripting (see scripting docs or forum)
    If you can do it with a script in the desktop version, that script will likely also run in ID Server. (see server forum).
    If you can specify missing features not achievable thru scripting or manual use, reconsider to write a plugin (this forum).
    A seasoned C++ programmer will need a few months to learn the basics, wade thru tons of documentation etc. Alternatively consider to hire a consultant to do the development work for you.
    Dirk

Maybe you are looking for