Java Code Examples for java.awt.dnd.DragSource#isDragImageSupported()

The following examples show how to use java.awt.dnd.DragSource#isDragImageSupported() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageDecoratedDnD.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
}
 
Example 2
Source File: ImageDecoratedDnD.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
}
 
Example 3
Source File: ImageDecoratedDnD.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
}
 
Example 4
Source File: ImageDecoratedDnD.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
}
 
Example 5
Source File: ImageDecoratedDnD.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
}
 
Example 6
Source File: ImageDecoratedDnD.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
}
 
Example 7
Source File: ImageDecoratedDnD.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
}
 
Example 8
Source File: ImageDecoratedDnD.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
}
 
Example 9
Source File: ImageDecoratedDnD.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
}
 
Example 10
Source File: DockTab.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void dragGestureRecognized(DragGestureEvent dge) {
    DockableTransferable transferable = new DockableTransferable(mDockable);
    if (DragSource.isDragImageSupported()) {
        Point offset = new Point(dge.getDragOrigin());
        offset.x = -offset.x;
        offset.y = -offset.y;
        dge.startDrag(null, DragSource.isDragImageSupported() ? UIUtilities.getImage(this) : null, offset, transferable, null);
    } else {
        dge.startDrag(null, transferable);
    }
}
 
Example 11
Source File: OutlineHeader.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void dragGestureRecognized(DragGestureEvent dge) {
    if (mSortColumn != null && mOwner.allowColumnDrag()) {
        mOwner.setSourceDragColumn(mSortColumn);
        if (DragSource.isDragImageSupported()) {
            Point pt = dge.getDragOrigin();
            dge.startDrag(null, mOwner.getColumnDragImage(mSortColumn), new Point(-(pt.x - mOwner.getColumnStart(mSortColumn)), -pt.y), mSortColumn, this);
        } else {
            dge.startDrag(null, mSortColumn, this);
        }
        mSortColumn = null;
    }
}
 
Example 12
Source File: ImageDecoratedDnDInOut.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
    try {
        Point sourcePoint = dragSource.getLocationOnScreen();
        Dimension d = dragSource.getSize();
        sourcePoint.translate(d.width / 2, d.height / 2);

        Robot robot = new Robot();
        robot.mouseMove(sourcePoint.x, sourcePoint.y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        Thread.sleep(2000);
        for(int i = 0; i <100; ++i) {
            robot.mouseMove(
                sourcePoint.x + d.width / 2 + 10,
                sourcePoint.y + d.height);
            Thread.sleep(100);

            robot.mouseMove(sourcePoint.x, sourcePoint.y);
            Thread.sleep(100);

            robot.mouseMove(
                sourcePoint.x,
                sourcePoint.y + d.height);
            Thread.sleep(100);
        }
        sourcePoint.y += d.height;
        robot.mouseMove(sourcePoint.x, sourcePoint.y);
        Thread.sleep(100);

        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        Thread.sleep(4000);
    } catch( Exception e){
    e.printStackTrace();
        throw new RuntimeException("test failed: drop was not successful with exception " + e);
    }

}
 
Example 13
Source File: ImageDecoratedDnDInOut.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
    try {
        Point sourcePoint = dragSource.getLocationOnScreen();
        Dimension d = dragSource.getSize();
        sourcePoint.translate(d.width / 2, d.height / 2);

        Robot robot = new Robot();
        robot.mouseMove(sourcePoint.x, sourcePoint.y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        Thread.sleep(2000);
        for(int i = 0; i <100; ++i) {
            robot.mouseMove(
                sourcePoint.x + d.width / 2 + 10,
                sourcePoint.y + d.height);
            Thread.sleep(100);

            robot.mouseMove(sourcePoint.x, sourcePoint.y);
            Thread.sleep(100);

            robot.mouseMove(
                sourcePoint.x,
                sourcePoint.y + d.height);
            Thread.sleep(100);
        }
        sourcePoint.y += d.height;
        robot.mouseMove(sourcePoint.x, sourcePoint.y);
        Thread.sleep(100);

        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        Thread.sleep(4000);
    } catch( Exception e){
    e.printStackTrace();
        throw new RuntimeException("test failed: drop was not successful with exception " + e);
    }

}
 
Example 14
Source File: ImageDecoratedDnDInOut.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
    try {
        Point sourcePoint = dragSource.getLocationOnScreen();
        Dimension d = dragSource.getSize();
        sourcePoint.translate(d.width / 2, d.height / 2);

        Robot robot = new Robot();
        robot.mouseMove(sourcePoint.x, sourcePoint.y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        Thread.sleep(2000);
        for(int i = 0; i <100; ++i) {
            robot.mouseMove(
                sourcePoint.x + d.width / 2 + 10,
                sourcePoint.y + d.height);
            Thread.sleep(100);

            robot.mouseMove(sourcePoint.x, sourcePoint.y);
            Thread.sleep(100);

            robot.mouseMove(
                sourcePoint.x,
                sourcePoint.y + d.height);
            Thread.sleep(100);
        }
        sourcePoint.y += d.height;
        robot.mouseMove(sourcePoint.x, sourcePoint.y);
        Thread.sleep(100);

        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        Thread.sleep(4000);
    } catch( Exception e){
    e.printStackTrace();
        throw new RuntimeException("test failed: drop was not successful with exception " + e);
    }

}
 
Example 15
Source File: ImageDecoratedDnDInOut.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
    try {
        Point sourcePoint = dragSource.getLocationOnScreen();
        Dimension d = dragSource.getSize();
        sourcePoint.translate(d.width / 2, d.height / 2);

        Robot robot = new Robot();
        robot.mouseMove(sourcePoint.x, sourcePoint.y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        Thread.sleep(2000);
        for(int i = 0; i <100; ++i) {
            robot.mouseMove(
                sourcePoint.x + d.width / 2 + 10,
                sourcePoint.y + d.height);
            Thread.sleep(100);

            robot.mouseMove(sourcePoint.x, sourcePoint.y);
            Thread.sleep(100);

            robot.mouseMove(
                sourcePoint.x,
                sourcePoint.y + d.height);
            Thread.sleep(100);
        }
        sourcePoint.y += d.height;
        robot.mouseMove(sourcePoint.x, sourcePoint.y);
        Thread.sleep(100);

        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        Thread.sleep(4000);
    } catch( Exception e){
    e.printStackTrace();
        throw new RuntimeException("test failed: drop was not successful with exception " + e);
    }

}
 
Example 16
Source File: ImageDecoratedDnDInOut.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
    try {
        Point sourcePoint = dragSource.getLocationOnScreen();
        Dimension d = dragSource.getSize();
        sourcePoint.translate(d.width / 2, d.height / 2);

        Robot robot = new Robot();
        robot.mouseMove(sourcePoint.x, sourcePoint.y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        Thread.sleep(2000);
        for(int i = 0; i <100; ++i) {
            robot.mouseMove(
                sourcePoint.x + d.width / 2 + 10,
                sourcePoint.y + d.height);
            Thread.sleep(100);

            robot.mouseMove(sourcePoint.x, sourcePoint.y);
            Thread.sleep(100);

            robot.mouseMove(
                sourcePoint.x,
                sourcePoint.y + d.height);
            Thread.sleep(100);
        }
        sourcePoint.y += d.height;
        robot.mouseMove(sourcePoint.x, sourcePoint.y);
        Thread.sleep(100);

        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        Thread.sleep(4000);
    } catch( Exception e){
    e.printStackTrace();
        throw new RuntimeException("test failed: drop was not successful with exception " + e);
    }

}
 
Example 17
Source File: ImageDecoratedDnDInOut.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
    try {
        Point sourcePoint = dragSource.getLocationOnScreen();
        Dimension d = dragSource.getSize();
        sourcePoint.translate(d.width / 2, d.height / 2);

        Robot robot = new Robot();
        robot.mouseMove(sourcePoint.x, sourcePoint.y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        Thread.sleep(2000);
        for(int i = 0; i <100; ++i) {
            robot.mouseMove(
                sourcePoint.x + d.width / 2 + 10,
                sourcePoint.y + d.height);
            Thread.sleep(100);

            robot.mouseMove(sourcePoint.x, sourcePoint.y);
            Thread.sleep(100);

            robot.mouseMove(
                sourcePoint.x,
                sourcePoint.y + d.height);
            Thread.sleep(100);
        }
        sourcePoint.y += d.height;
        robot.mouseMove(sourcePoint.x, sourcePoint.y);
        Thread.sleep(100);

        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        Thread.sleep(4000);
    } catch( Exception e){
    e.printStackTrace();
        throw new RuntimeException("test failed: drop was not successful with exception " + e);
    }

}
 
Example 18
Source File: ImageDecoratedDnDInOut.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
    try {
        Point sourcePoint = dragSource.getLocationOnScreen();
        Dimension d = dragSource.getSize();
        sourcePoint.translate(d.width / 2, d.height / 2);

        Robot robot = new Robot();
        robot.mouseMove(sourcePoint.x, sourcePoint.y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        Thread.sleep(2000);
        for(int i = 0; i <100; ++i) {
            robot.mouseMove(
                sourcePoint.x + d.width / 2 + 10,
                sourcePoint.y + d.height);
            Thread.sleep(100);

            robot.mouseMove(sourcePoint.x, sourcePoint.y);
            Thread.sleep(100);

            robot.mouseMove(
                sourcePoint.x,
                sourcePoint.y + d.height);
            Thread.sleep(100);
        }
        sourcePoint.y += d.height;
        robot.mouseMove(sourcePoint.x, sourcePoint.y);
        Thread.sleep(100);

        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        Thread.sleep(4000);
    } catch( Exception e){
    e.printStackTrace();
        throw new RuntimeException("test failed: drop was not successful with exception " + e);
    }

}
 
Example 19
Source File: ImageDecoratedDnDInOut.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
    try {
        Point sourcePoint = dragSource.getLocationOnScreen();
        Dimension d = dragSource.getSize();
        sourcePoint.translate(d.width / 2, d.height / 2);

        Robot robot = new Robot();
        robot.mouseMove(sourcePoint.x, sourcePoint.y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        Thread.sleep(2000);
        for(int i = 0; i <100; ++i) {
            robot.mouseMove(
                sourcePoint.x + d.width / 2 + 10,
                sourcePoint.y + d.height);
            Thread.sleep(100);

            robot.mouseMove(sourcePoint.x, sourcePoint.y);
            Thread.sleep(100);

            robot.mouseMove(
                sourcePoint.x,
                sourcePoint.y + d.height);
            Thread.sleep(100);
        }
        sourcePoint.y += d.height;
        robot.mouseMove(sourcePoint.x, sourcePoint.y);
        Thread.sleep(100);

        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        Thread.sleep(4000);
    } catch( Exception e){
    e.printStackTrace();
        throw new RuntimeException("test failed: drop was not successful with exception " + e);
    }

}
 
Example 20
Source File: ImageDecoratedDnDInOut.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
    try {
        Point sourcePoint = dragSource.getLocationOnScreen();
        Dimension d = dragSource.getSize();
        sourcePoint.translate(d.width / 2, d.height / 2);

        Robot robot = new Robot();
        robot.mouseMove(sourcePoint.x, sourcePoint.y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        Thread.sleep(2000);
        for(int i = 0; i <100; ++i) {
            robot.mouseMove(
                sourcePoint.x + d.width / 2 + 10,
                sourcePoint.y + d.height);
            Thread.sleep(100);

            robot.mouseMove(sourcePoint.x, sourcePoint.y);
            Thread.sleep(100);

            robot.mouseMove(
                sourcePoint.x,
                sourcePoint.y + d.height);
            Thread.sleep(100);
        }
        sourcePoint.y += d.height;
        robot.mouseMove(sourcePoint.x, sourcePoint.y);
        Thread.sleep(100);

        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        Thread.sleep(4000);
    } catch( Exception e){
    e.printStackTrace();
        throw new RuntimeException("test failed: drop was not successful with exception " + e);
    }

}