Drag and drop an image over a JPanel (only change position on same JPanel)

Hi all,
there is JPanel added to a JDialog.
There is a BufferedImage on the JPanel: I need to let the image be dragged and dropped in another position over the same JPanel and read the new position's coordinates.
(Maybe the image has to be wrapped in a JComponent?)
Thanks in advance for any suggestions.
Ludovico

(Maybe the image has to be wrapped in a JComponent?)Just add the image to a JLabel and add the label to the panel.

Similar Messages

  • Which Listener I should use if I drag and Drop an image/icon into a JPanel?

    Dar Friends:
    Happy new year.
    I try to drag and Drop an image/icon into a JPanel, and hope I can immediately detect it after DND,
    Which Listener I should use in this JPanel if I drag and Drop an image/icon into a JPanel??
    Thanks

    Thank camickr .
    I can dnd an image into a JPanel called JPanelOld already, I hope to use another JPanel or JTree to listen to any Dropped Image in JPanelOld later on so I can take some action in another JPanel or JTree.
    so what kind of Listener I should use for my purpose??
    where to add this Listeners??
    Happy New Year.

  • When i drag and drop an image on my site. it gives the following error. "Unable to access local files due to browser security settings. To overcome this, follo"

    I am using the firefox version 17 and when i drag and drop an image on my website. It gives me the following error.
    Unable to access local files due to browser security settings. To overcome this, follow these steps: (1) Enter "about:config" in the URL field; (2) Right click and select New->Boolean; (3) Enter "signed.applets.codebase_principal_support" (without the quotes) as a new preference name; (4) Click OK and try loading the file again. Or go to the homepage for a link to the tutorial on how to do it.
    I have completed the above steps and it is still showing the same error message. Any help would be highly appreciated.
    Thanks.

    Thanks kumars ,
    I have a specific drag and drop area on our website. This works fine for all earlier releases of Firefox after these security settings
    "(1) Enter "about:config" in the URL field; (2) Right click and select New->Boolean; (3) Enter "signed.applets.codebase_principal_support" (without the quotes) as a new preference name; (4) Click OK and try loading the file again."
    Bust these settings not work for me in Firefox 17.
    Yes the drag and drop functionality is java script based and i am not using any script blocker addons.

  • How to drag and drop href image from webbrowser to office using vsto c# wpf?

    I want to drag and drop href images from web browser to office using C# wpf. Is it possible to drag href images ? give me the solution

    Hi,
    Are you developing an Office Add-in application? Do you mean you hold a wpf Web Browser control in the Office Add-in project?
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • BUG - Drag and drop an image, only working at the 2nd try

    I use the last version of JDeveloper : 11g R1 : 11.1.1.2.0
    I try to drag and drop an image in a facet of a panelsplitter.
    Once the page is loaded, the first time I try to drag the image, it does not work : the image does not follow the mouse.
    When I try to drag the image again, then it works : the image follow the mouse
    So I don't think it's related to the destination/target.
    I feel it's so simple, since it just requires to add <af:componentDragSource/> inside <af:image/>
    that if it does not work, it can only be a bug in the functionality offered by ADF ...
    Or maybe there is something wrong with the generation of the page ?
    I get this message in blue in the "running log of WebLogic" :
    <FormRenderer><setupEncodingContext> Multiple forms detected on viewId: /myPage.jspx. Rich client currently has some limitations in dealing with multiple forms.
    Please note that I use jsp:include inside f:subview to include fragments (.jsff) so that the source and the destination are not in the same file, the source in a .jsff while the destination is on the main .jspx
    The code related to the drag and drop :
    <af:form id="form">
    <af:panelSplitter orientation="vertical" splitterPosition="70" id="psHeader" clientComponent="true">
    <af:panelAccordion id="paPref" discloseNone="true" styleClass="fullSize">
    <af:showDetailItem id="sdiTemp" text="Templates">
    <af:panelBox>
    <af:panelGroupLayout id="pglTemp" layout="scroll">
    <af:panelList id="plTemp" rows="2">
    <af:image id="imTemp2up" source="/images/anImage.jpg" inlineStyle="" shortDesc="...">
    <af:componentDragSource/>
    </af:image>
    <f:facet name="second">
    <af:dropTarget dropListener="#{dropHandler.handleComponentMove}" actions="MOVE">
    <af:dataFlavor flavorClass="javax.faces.component.UIComponent"/>
    </af:dropTarget>
    Any idea ?
    Thanks in advance,
    JP

    Hi,
    no bug that I can detect here as it works for me with the same setup. How likely is it that the image is too small so that you don't grab it probably the first time?
    Frank

  • How to drag and drop an Image between two JPanels inside a Split Pane

    I'm tring to do that, and my actual problem is as follows:
    I drag the Image from the bottomPanel but I can't drop it in the topPanel, I'm using this classes:
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import java.awt.dnd.*;
    import java.awt.datatransfer.*;
    import java.awt.image.*;
    public class MoveableComponentsContainer extends JSplitPane {     
         public DragSource dragSource;
         public DropTarget dropTarget;
    public JPanel topPanel = new JPanel();
    public JPanel bottomPanel = new JPanel();
         public int ancho;
    public int alto;
    public MoveableLabel lab1,lab2,lab3,lab4;
    public Icon ico1, ico2,ico3,ico4;
    private static BufferedImage buffImage = null; //buff image
         private static Point cursorPoint = new Point();
    public int getMaximumDividerLocation() {
    return ( ( int ) ( alto * .85 ) );
    public int getMinimumDividerLocation() {
    return( ( int ) ( alto * .85 ) );
         public MoveableComponentsContainer(int Weight, int Height ) {
    alto = Height;
    ancho = Weight;
    setOrientation( VERTICAL_SPLIT);
    setDividerSize(2);
    getMaximumDividerLocation();
    getMinimumDividerLocation();
    setPreferredSize(new Dimension( (int) ( Weight * .99 ), (int) ( Height * .94 ) ) );
    setDividerLocation( getMaximumDividerLocation() );
    System.out.println( " getDividerLocation() = " + getDividerLocation() );
    topPanel.setName("topPanel");
    bottomPanel.setName("bottomPanel");
    bottomPanel.setPreferredSize( new Dimension( (int) ( Weight * .99 ), (int) ( ( Height * .94 ) * .15 ) ) );
    bottomPanel.setMaximumSize( new Dimension( (int) ( Weight * .99 ), (int) ( ( Height * .94 ) * .15 ) ) );
    bottomPanel.setMinimumSize( new Dimension( (int) ( Weight * .99 ), (int) ( ( Height * .94 ) * .15 ) ) );
    topPanel. setPreferredSize( new Dimension( (int) ( Weight * .99 ), (int) ( ( Height * .94 ) * .85 ) ) );
    topPanel. setMaximumSize( new Dimension( (int) ( Weight * .99 ), (int) ( ( Height * .94 ) * .85 ) ) );
    topPanel. setMinimumSize( new Dimension( (int) ( Weight * .99 ), (int) ( ( Height * .94 ) * .85 ) ) );
    bottomPanel.setEnabled(true);
    bottomPanel.setVisible(true);
    bottomPanel.setBackground( new Color( 57,76,123 ) );
    topPanel. setEnabled(true);
    topPanel. setVisible(true);
    topPanel. setBackground( new Color( 57,76,123 ) );
    setBottomComponent( bottomPanel );
    setTopComponent( topPanel );
    setOneTouchExpandable( false );
    bottomPanel.setBorder(BorderFactory.createTitledBorder("Drag and Drop Test"));
              setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED, Color.white, Color.gray));
    bottomPanel.setLayout( new FlowLayout() );
    topPanel.setLayout(new FlowLayout());
              addMoveableComponents();
         private void addMoveableComponents() {
    ico1 = new ImageIcon( "/usr/local/installers/java/lll/DnD/switchm.gif");
    lab1 = new MoveableLabel("Centrales", ico1, topPanel );
    lab1.setName("labelOne");
    bottomPanel.add( lab1 );
              lab2 = new MoveableLabel("Destinos", ico1, topPanel);
    lab2.setName("labelTwo");
              bottomPanel.add( lab2 );
              lab3 = new MoveableLabel("Registros", ico1, topPanel );
    lab3.setName("labelThree");
              bottomPanel.add( lab3 );
              lab4 = new MoveableLabel("Parametros", ico1, topPanel);
    lab4.setName("labelFour");
              bottomPanel.add( lab4 );
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import java.awt.dnd.*;
    import java.awt.datatransfer.*;
    public class MoveableLabel extends JLabel implements Transferable {
    final static int FILE = 0;
    final static int STRING = 1;
    final static int IMAGE = 2;
    DataFlavor flavors[] = { DataFlavor.javaFileListFlavor,
    DataFlavor.stringFlavor,
    DataFlavor.imageFlavor };
    public JPanel PanelDestino;
    public JPanel PanelOrigen;
    public DropTarget dropTarget;
    public DropTargetListener dropTargetLis;
         private static final Border border = BorderFactory.createLineBorder(Color.black, 1);
         public MoveableLabel(String text, Icon ic, JPanel DestPanel) {
              super( text, ic, TRAILING);
    PanelDestino = DestPanel;
              MouseEventForwarder forwarder = new MouseEventForwarder();
              addMouseListener(forwarder);
              addMouseMotionListener(forwarder);
              setBorder(border);
              setBounds(0,0,50,100);
              setOpaque(true);
    setTransferHandler(new TransferHandler("text"));
    setBackground( new Color( 57,76,123 ) );
    public synchronized DataFlavor[] getTransferDataFlavors() {
         return flavors;
    public boolean isDataFlavorSupported(DataFlavor flavor) {
    boolean b = false;
    b |= flavor.equals(flavors[ FILE ]);
    b |= flavor.equals(flavors[STRING]);
    b |= flavor.equals(flavors[ IMAGE]);
    return (b);
    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, java.io.IOException {
    return this;
         final class MouseEventForwarder extends MouseInputAdapter {
              public void mousePressed(MouseEvent e) {
                   Container parent = getParent();
    Container brother = (Container)PanelDestino;
    System.out.println( "Parent 1 = " + parent.getName() );
    System.out.println( "Destino 1 = " + brother.getName() );
    JComponent c = (JComponent) e.getSource();
    System.out.println( "getsource() = " + c.getName() );
    TransferHandler th = c.getTransferHandler();
    th.exportAsDrag( c, e, TransferHandler.COPY_OR_MOVE );
    dropTarget = getDropTarget();
    System.out.println( "dropTarget.getComponent().getName() = " + dropTarget.getComponent().getName() );
    for ( int a=0; a < parent.getComponentCount(); a++ ) {
    parent.getComponent( a ).setEnabled( false );
    brother.setDropTarget( dropTarget );
    System.out.println( "dropTarget.getComponent().getName() = " + dropTarget.getComponent().getName() );
              public void mouseReleased(MouseEvent e) {
                   Container parent = getParent();
    Container brother = PanelDestino;
    System.out.println( "Parent 2 = " + parent.getName() );
    System.out.println( "Destino 2 = " + PanelDestino.getName() );
    parent.setEnabled( true );
    brother.setEnabled( false );
    for ( int a=0; a < parent.getComponentCount(); a++ ) {
    parent.getComponent( a ).setEnabled( true );
    import java.awt.*;
    import javax.swing.*;
    public class TestDragComponent extends JFrame {
         public TestDragComponent() {
    super("TestDragComponent");
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension dm = new Dimension();
    dm = tk.getScreenSize();
    System.out.println(dm.height);
    System.out.println(dm.width );
    Container cntn = getContentPane();
    cntn.setFont(new Font("Helvetica", Font.PLAIN, 14));
    cntn.add(new MoveableComponentsContainer(dm.width,dm.height));
              pack();
              setVisible(true);
         public static void main(String[] args) {
              new TestDragComponent();

    Ok I found the answer to your problem. If you download the tutorial they have the code there it's in one folder. I hope this helps.
    http://java.sun.com/docs/books/tutorial/

  • Drag and drop a image from html page into flex

    how can i drag a image form the html page and drop it into
    the flex application.

    Hi,
    There's no direct support for this. But you could implement
    drag and drop the way you normally would in javascript. Except
    here, on mouseUp over a div encapsulating the object or embed tag
    (the flash object), you'll need to make a call into actionscript
    from javascript indicating that a drag and drop happened.
    For more info, see
    how
    to drag and drop using javascript and
    actionscript
    and javascript communication

  • Drag and Drop an image

    Can anyone recommend me a good tutorial on how to drag and drop or even resize an image in a panel ?

    I'm back.
    I wrote a 2 classes appli that allow to move and resize images displayed in a panel.
    The first class is the most interesting one. It describes an object which extends Rectangle and manage an Image. This class names TransformableImage extends Rectangle because we need to know the bounds of the rectangle, where the image is contained in, to allow mouse interactions through the panel.
    The behavior we want is to change the kind of cursors according to the position of the mouse on the panel :
    if the mouse is out of any images the cursor is the default one. If the cursor is on an image, it can be a move cursor in the center of the image or one of the resize cursors if the mouse is on the border of the image.
    Here is the class :
    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 :
    }And now, we need to create the panel where we are going to draw the images and interact with them with the mouse. In fact we need a paintComponent method used to draw the images and a Mouse(Motion)Listener to manage the required mouse events.
    We also have to create a method to set the convenient cursor according to tha position of the mouse over the images.
    Here is the class :
    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("image1.gif"));
              images.add(new TransformableImage("image2.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);
    }If you want more information tell me.
    ------- Here is the unformatted version -----
    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 :
    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("image1.gif"));
              images.add(new TransformableImage("image2.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);
    Denis

  • Master Slide issue - drag and drop alt slide over theme slide

    Keynote on my MacPro: Where before on the previous version I could in Master Slides drag and drop an alternative look over a theme slide to change that slide only and no affecting the entire presentation which was most useful, now that seems no longer an option unless there's something I can't find to do that. When viewing Master Slides now you cannot see the presentation you're working on. Previously I would set up several slides with different looks and where needed drop that look over a slide and it would override the theme slide without all slides being affected. Qny thought guys? Barry

    Although I have been answering quite a lot of questions about Drag&Drop functionality (not a widget), you are the first to mention such problems.  Personally I never had problems, only when not respecting the design of the interaction or doing something stupid. If you are the only user to have such experience (at least for what I hear in these forums and on social media), I don't see why an upgrade should be expected? Did you log the problem? Are you sure that the project is not corrupted?
    The jigsaw learning interaction is pretty simple, also limited, don't know what are your problems there?
    Are you sure that all objects used in the D&D (drag sources and drop targets) are visible in output. It is a bit confusing in CP8 because the eye icon is used both for visible in output for objects in Properties panel, and for showing the links in D&D in the D&D panel. Can you see the links? Did you avoid overlapping of objects? Did you not rename an object after creating the D&D interaction, because that will break the link from/to that object? I mentioned this in my last article: Drag&Drop tips - Captivate blog
    I am just trying to find out what is going wrong, bit curious about this rare case.

  • Is there any view where I can drag-and-drop an image to another app?

    I'm new to LR3.4.   I'm building books using Luminix PhotoFusion and used to be able to drag-and-drop images directly from PSE5 into Luminix.   With PSE8, that capability was lost and I had to bring up the file properties, go to the containing folder, and drag-and-drop from there.   This greatly slows down the process.   I don't want to export the images because then I have multiple copies to maintain.  
    Does anyone have suggestions for a workflow for this?   I haven't looked into publishing yet but that also seems to replicate like to Flickr.
    Thanks

    I've tried drag-and-drop from the grid, filmstrip, etc.   I get the universal circle with a slash.... no go.  I've tried dragging to WORD, PowerPoint, IrfanView, PhotoFusion, and all have the same result.
    I'm running Win7 64-bit.

  • Can I drag and drop an image into Photoshop

    hello, as a first time user ive using photoshop on a mac at school. i just downloaded photoshop on my pc. i cant insert my image onto photoshop. the way we do it in class is drag the image to the ps icon and it will open with the pic. please help and if theres anything i need to know please inform me also. thanks for all the help!!! ps im also learning how to use intuos tablet with it

    Welcome to the forum. I don't own a mac, so I may not be as accurate as I would like.
    It may require photoshop to already be running for the drag and drop to work. Try minimizing photoshop then drag and drop.

  • Drag-and-drop for image stacks

    I'd like to be able to drag and drop image stacks from one folder to the next. Currently, when I drag and drop it just grabs one of the images from the stack and leaves the others behind.
    I can expand the stack and then drag and drop all of them, but the stack itself is lost--I have to go to the destination directory and re-stack the images.
    Bart

    I've discovered (and its nowhere in the documentation as far as I can see) that if you select the bottom slide in a stack .. ie the bottom left hand corner of the "reperesenation of the lower slides" you can drag and drop the stack(s) in to another folder.
    Unfortunately they don't remain stacked ..Here's another vote for persistent stacks.
    Pete Roberts

  • Canu00B4t Drag and drop a service over the model Workspace

    Hi guys,
    I´m trying to consume an Eservice published in the ServiceRegistry. I can see all the services in the result list when i search them, but when i try to drag and drop any of those service over the model workplace nothing happens.
    I hope someone can help me to solve this problem.
    Thanks in advance,
    Regards,
    Diego.

    Hi
    Another thing I'd suggest to do (to better understand what goes wrong) is to make sure the VC console is open.
    Please goto View menu and check the 'Console' entry (it should be visible in the bottom of the application)
    Once you reproduce your problem the console should show information on errors - please put them here and I'll try to analyze the problem
    Guy

  • Trying to drag and drop a text parameter, but it only applies to one letter

    Hiya,
    In Motion 3, you could drag and drop a Text - Style Parameter to another text object.
    Now, in Motion 4, when I try to drag a Parameter it only applies to the first letter of my text object.
    So when I drag my Glow from one object to another, my Bleary In Behavior has a blue glow on T in THIS and a yellow glow on HIS in THIS.
    I'm guessing this has to do with the ability to adjust each letter with the glyph tool. However, it won't allow me to drag the Parameter to each individual letter...
    Which I see a need for...
    But why would I want to do a time consuming thing like that?
    It's stupid.
    Any advice is much appreciated!
    Thank you

    Well, I'm not sure what to say. I can't replicate your problem. I can drag the outline parameters onto a text object in the viewer, layers pane, or timeline and it copies it exactly as it did in Motion 3, over the entire text object.
    However, if I have the glyph tool selected and try to do the same thing, it crashes Motion 100% of the time.
    Neither situation is what you're reporting though. It helped me find a bug, and something to avoid however.
    Andy

  • Drag and drop to CD or DVD is only writing a shortcut?

    I'm trying to drag and drop files to a CD and no matter what type of file I drag to the finder window, it only produces a shortcut. I even tried different filetypes and sizes and media and had the same issue. Any ideas?

    Hi,
    That's normal. Once you burn the CD the files will really be there.
    http://www.apple.com/pro/tips/burningaliases.html

Maybe you are looking for

  • Issue playing videos in iTunes with Windows 7 x64

    Hi, hoping someone can help. I  am running Windows 7 64 bit, and have installed the latest version of iTunes. I have around 150 HD movies stored on my PC, which were previously from an iMac I owned. Whenever I play one of these, the video keeps stutt

  • Can i have tow HttpService in the same application???

    I try to use tow HttpService (one for delete row in a table and the other for read the table): <mx:HTTPService id="listcls" url=" http://127.0.0.1:32000/affcls.php" useProxy="false" method="POST"> <mx:request xmlns=""> <clsci>{clsci.text}</clsci><cls

  • String comparision

    String a = "alpha"; String b = "xxxxalphayyyyyyy"; is there any method that returns true, if I had to check if String b contains a, otherwise false.....

  • Sticky footer in Fluid Grid layouts (was: sticky footer)

    Is there a simple solution to putting a sticky footer on the bottom of a page (not fixed on the bottom of the screen) that actually works with fluid grid layouts? I've looked at several options but nothing seems to work in all browsers commonly in us

  • Where is Contact Sheet II in CS4?

    Just upgraded to CS4 and cannot find Contact Sheet II under File>Automate. Went back to my old CS and pulled up the feature only to find out that when I went under Source Images> Folders>Choose... the chosen folder has all the photos grayed out.I'm o