java.awt.Robot#mouseWheel ( )源码实例Demo

下面列出了java.awt.Robot#mouseWheel ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: nebula   文件: AbstractVTestCase.java
public void mouseWheel(int count) {
	// Event event = new Event();
	// event.type = SWT.MouseWheel;
	// event.data = VTracker.getActiveControl();
	// event.detail = SWT.SCROLL_LINE;
	// event.x = x;
	// event.y = y;
	// event.count = count;
	// display.post(event);
	try {
		Robot robot = new Robot();
		robot.mouseWheel(count);
	} catch (Exception e) {
		e.printStackTrace();
	}
	pause(delay);
}
 
源代码2 项目: openjdk-jdk9   文件: MouseWheelAbsXY.java
private static void test(GraphicsConfiguration gc) throws AWTException {
    final Window frame = new Frame(gc);
    try {
        frame.addMouseWheelListener(e -> {
            wheelX = e.getXOnScreen();
            wheelY = e.getYOnScreen();
            done = true;
        });
        frame.setSize(300, 300);
        frame.setVisible(true);

        final Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.setAutoWaitForIdle(true);
        mouseX = frame.getX() + frame.getWidth() / 2;
        mouseY = frame.getY() + frame.getHeight() / 2;

        robot.mouseMove(mouseX, mouseY);
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
        robot.mouseWheel(10);

        validate();
    } finally {
        frame.dispose();
    }
}
 
private static void test(Robot robot) throws Exception {
    SwingUtilities.invokeAndWait(() -> {
        Point locationOnScreen = scrollPane.getLocationOnScreen();
        point = new Point(
                locationOnScreen.x + scrollPane.getWidth() / 2,
                locationOnScreen.y + scrollPane.getHeight() / 2);
    });

    robot.mouseMove(point.x, point.y);
    robot.waitForIdle();

    // vertical scroll bar is enabled
    initScrollPane(true, false);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(true, false);

    // vertical scroll bar is enabled + shift
    initScrollPane(true, false);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, false);

    // horizontal scroll bar is enabled
    initScrollPane(false, true);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(false, true);

    // horizontal scroll bar is enabled + shift
    initScrollPane(false, true);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, true);

    // both scroll bars are enabled
    initScrollPane(true, true);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(true, false);

    // both scroll bars are enabled + shift
    initScrollPane(true, true);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, true);
}
 
private static void test(Robot robot) throws Exception {
    SwingUtilities.invokeAndWait(() -> {
        Point locationOnScreen = scrollPane.getLocationOnScreen();
        point = new Point(
                locationOnScreen.x + scrollPane.getWidth() / 2,
                locationOnScreen.y + scrollPane.getHeight() / 2);
    });

    robot.mouseMove(point.x, point.y);
    robot.waitForIdle();

    // vertical scroll bar is enabled
    initScrollPane(true, false);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(true, false);

    // vertical scroll bar is enabled + shift
    initScrollPane(true, false);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, false);

    // horizontal scroll bar is enabled
    initScrollPane(false, true);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(false, true);

    // horizontal scroll bar is enabled + shift
    initScrollPane(false, true);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, true);

    // both scroll bars are enabled
    initScrollPane(true, true);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(true, false);

    // both scroll bars are enabled + shift
    initScrollPane(true, true);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, true);
}
 
源代码5 项目: jdk8u60   文件: bug8033000.java
public static void main(String[] args) throws Exception {

        Robot robot = new Robot();
        robot.setAutoDelay(50);

        SwingUtilities.invokeAndWait(bug8033000::createAndShowGUI);
        robot.waitForIdle();

        SwingUtilities.invokeAndWait(() -> {
            Point locationOnScreen = scrollPane.getLocationOnScreen();
            point = new Point(
                    locationOnScreen.x + scrollPane.getWidth() / 2,
                    locationOnScreen.y + scrollPane.getHeight() / 2);
        });

        robot.mouseMove(point.x, point.y);
        robot.waitForIdle();

        // vertical scroll bar is enabled
        initScrollPane(true, false);
        robot.waitForIdle();
        robot.mouseWheel(delta);
        robot.waitForIdle();
        checkScrollPane(true);

        // vertical scroll bar is enabled + shift
        initScrollPane(true, false);
        robot.waitForIdle();
        robot.keyPress(KeyEvent.VK_SHIFT);
        robot.mouseWheel(delta);
        robot.keyRelease(KeyEvent.VK_SHIFT);
        robot.waitForIdle();
        checkScrollPane(true);

        // horizontal scroll bar is enabled
        initScrollPane(false, true);
        robot.waitForIdle();
        robot.mouseWheel(delta);
        robot.waitForIdle();
        checkScrollPane(false);

        // horizontal scroll bar is enabled + shift
        initScrollPane(false, true);
        robot.waitForIdle();
        robot.keyPress(KeyEvent.VK_SHIFT);
        robot.mouseWheel(delta);
        robot.keyRelease(KeyEvent.VK_SHIFT);
        robot.waitForIdle();
        checkScrollPane(false);

        // both scroll bars are enabled
        initScrollPane(true, true);
        robot.waitForIdle();
        robot.mouseWheel(delta);
        robot.waitForIdle();
        checkScrollPane(true);

        // both scroll bars are enabled + shift
        initScrollPane(true, true);
        robot.waitForIdle();
        robot.keyPress(KeyEvent.VK_SHIFT);
        robot.mouseWheel(delta);
        robot.keyRelease(KeyEvent.VK_SHIFT);
        robot.waitForIdle();
        checkScrollPane(false);
    }
 
private static void test(Robot robot) throws Exception {
    SwingUtilities.invokeAndWait(() -> {
        Point locationOnScreen = scrollPane.getLocationOnScreen();
        point = new Point(
                locationOnScreen.x + scrollPane.getWidth() / 2,
                locationOnScreen.y + scrollPane.getHeight() / 2);
    });

    robot.mouseMove(point.x, point.y);
    robot.waitForIdle();

    // vertical scroll bar is enabled
    initScrollPane(true, false);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(true, false);

    // vertical scroll bar is enabled + shift
    initScrollPane(true, false);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, false);

    // horizontal scroll bar is enabled
    initScrollPane(false, true);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(false, true);

    // horizontal scroll bar is enabled + shift
    initScrollPane(false, true);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, true);

    // both scroll bars are enabled
    initScrollPane(true, true);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(true, false);

    // both scroll bars are enabled + shift
    initScrollPane(true, true);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, true);
}
 
private static void test(Robot robot) throws Exception {
    SwingUtilities.invokeAndWait(() -> {
        Point locationOnScreen = scrollPane.getLocationOnScreen();
        point = new Point(
                locationOnScreen.x + scrollPane.getWidth() / 2,
                locationOnScreen.y + scrollPane.getHeight() / 2);
    });

    robot.mouseMove(point.x, point.y);
    robot.waitForIdle();

    // vertical scroll bar is enabled
    initScrollPane(true, false);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(true, false);

    // vertical scroll bar is enabled + shift
    initScrollPane(true, false);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, false);

    // horizontal scroll bar is enabled
    initScrollPane(false, true);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(false, true);

    // horizontal scroll bar is enabled + shift
    initScrollPane(false, true);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, true);

    // both scroll bars are enabled
    initScrollPane(true, true);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(true, false);

    // both scroll bars are enabled + shift
    initScrollPane(true, true);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, true);
}
 
private static void test(Robot robot) throws Exception {
    SwingUtilities.invokeAndWait(() -> {
        Point locationOnScreen = scrollPane.getLocationOnScreen();
        point = new Point(
                locationOnScreen.x + scrollPane.getWidth() / 2,
                locationOnScreen.y + scrollPane.getHeight() / 2);
    });

    robot.mouseMove(point.x, point.y);
    robot.waitForIdle();

    // vertical scroll bar is enabled
    initScrollPane(true, false);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(true, false);

    // vertical scroll bar is enabled + shift
    initScrollPane(true, false);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, false);

    // horizontal scroll bar is enabled
    initScrollPane(false, true);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(false, true);

    // horizontal scroll bar is enabled + shift
    initScrollPane(false, true);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, true);

    // both scroll bars are enabled
    initScrollPane(true, true);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(true, false);

    // both scroll bars are enabled + shift
    initScrollPane(true, true);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, true);
}
 
private static void test(Robot robot) throws Exception {
    SwingUtilities.invokeAndWait(() -> {
        Point locationOnScreen = scrollPane.getLocationOnScreen();
        point = new Point(
                locationOnScreen.x + scrollPane.getWidth() / 2,
                locationOnScreen.y + scrollPane.getHeight() / 2);
    });

    robot.mouseMove(point.x, point.y);
    robot.waitForIdle();

    // vertical scroll bar is enabled
    initScrollPane(true, false);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(true, false);

    // vertical scroll bar is enabled + shift
    initScrollPane(true, false);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, false);

    // horizontal scroll bar is enabled
    initScrollPane(false, true);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(false, true);

    // horizontal scroll bar is enabled + shift
    initScrollPane(false, true);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, true);

    // both scroll bars are enabled
    initScrollPane(true, true);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(true, false);

    // both scroll bars are enabled + shift
    initScrollPane(true, true);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, true);
}
 
private static void test(Robot robot) throws Exception {
    SwingUtilities.invokeAndWait(() -> {
        Point locationOnScreen = scrollPane.getLocationOnScreen();
        point = new Point(
                locationOnScreen.x + scrollPane.getWidth() / 2,
                locationOnScreen.y + scrollPane.getHeight() / 2);
    });

    robot.mouseMove(point.x, point.y);
    robot.waitForIdle();

    // vertical scroll bar is enabled
    initScrollPane(true, false);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(true, false);

    // vertical scroll bar is enabled + shift
    initScrollPane(true, false);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, false);

    // horizontal scroll bar is enabled
    initScrollPane(false, true);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(false, true);

    // horizontal scroll bar is enabled + shift
    initScrollPane(false, true);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, true);

    // both scroll bars are enabled
    initScrollPane(true, true);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(true, false);

    // both scroll bars are enabled + shift
    initScrollPane(true, true);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, true);
}
 
private static void test(Robot robot) throws Exception {
    SwingUtilities.invokeAndWait(() -> {
        Point locationOnScreen = scrollPane.getLocationOnScreen();
        point = new Point(
                locationOnScreen.x + scrollPane.getWidth() / 2,
                locationOnScreen.y + scrollPane.getHeight() / 2);
    });

    robot.mouseMove(point.x, point.y);
    robot.waitForIdle();

    // vertical scroll bar is enabled
    initScrollPane(true, false);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(true, false);

    // vertical scroll bar is enabled + shift
    initScrollPane(true, false);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, false);

    // horizontal scroll bar is enabled
    initScrollPane(false, true);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(false, true);

    // horizontal scroll bar is enabled + shift
    initScrollPane(false, true);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, true);

    // both scroll bars are enabled
    initScrollPane(true, true);
    robot.waitForIdle();
    robot.mouseWheel(delta);
    robot.waitForIdle();
    checkScrollPane(true, false);

    // both scroll bars are enabled + shift
    initScrollPane(true, true);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.mouseWheel(delta);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.waitForIdle();
    checkScrollPane(false, true);
}
 
源代码12 项目: jdk8u-jdk   文件: bug8033000.java
public static void main(String[] args) throws Exception {

        Robot robot = new Robot();
        robot.setAutoDelay(50);

        SwingUtilities.invokeAndWait(bug8033000::createAndShowGUI);
        robot.waitForIdle();

        SwingUtilities.invokeAndWait(() -> {
            Point locationOnScreen = scrollPane.getLocationOnScreen();
            point = new Point(
                    locationOnScreen.x + scrollPane.getWidth() / 2,
                    locationOnScreen.y + scrollPane.getHeight() / 2);
        });

        robot.mouseMove(point.x, point.y);
        robot.waitForIdle();

        // vertical scroll bar is enabled
        initScrollPane(true, false);
        robot.waitForIdle();
        robot.mouseWheel(delta);
        robot.waitForIdle();
        checkScrollPane(true);

        // vertical scroll bar is enabled + shift
        initScrollPane(true, false);
        robot.waitForIdle();
        robot.keyPress(KeyEvent.VK_SHIFT);
        robot.mouseWheel(delta);
        robot.keyRelease(KeyEvent.VK_SHIFT);
        robot.waitForIdle();
        checkScrollPane(true);

        // horizontal scroll bar is enabled
        initScrollPane(false, true);
        robot.waitForIdle();
        robot.mouseWheel(delta);
        robot.waitForIdle();
        checkScrollPane(false);

        // horizontal scroll bar is enabled + shift
        initScrollPane(false, true);
        robot.waitForIdle();
        robot.keyPress(KeyEvent.VK_SHIFT);
        robot.mouseWheel(delta);
        robot.keyRelease(KeyEvent.VK_SHIFT);
        robot.waitForIdle();
        checkScrollPane(false);

        // both scroll bars are enabled
        initScrollPane(true, true);
        robot.waitForIdle();
        robot.mouseWheel(delta);
        robot.waitForIdle();
        checkScrollPane(true);

        // both scroll bars are enabled + shift
        initScrollPane(true, true);
        robot.waitForIdle();
        robot.keyPress(KeyEvent.VK_SHIFT);
        robot.mouseWheel(delta);
        robot.keyRelease(KeyEvent.VK_SHIFT);
        robot.waitForIdle();
        checkScrollPane(false);
    }
 
源代码13 项目: jdk8u-dev-jdk   文件: bug8033000.java
public static void main(String[] args) throws Exception {

        Robot robot = new Robot();
        robot.setAutoDelay(50);

        SwingUtilities.invokeAndWait(bug8033000::createAndShowGUI);
        robot.waitForIdle();

        SwingUtilities.invokeAndWait(() -> {
            Point locationOnScreen = scrollPane.getLocationOnScreen();
            point = new Point(
                    locationOnScreen.x + scrollPane.getWidth() / 2,
                    locationOnScreen.y + scrollPane.getHeight() / 2);
        });

        robot.mouseMove(point.x, point.y);
        robot.waitForIdle();

        // vertical scroll bar is enabled
        initScrollPane(true, false);
        robot.waitForIdle();
        robot.mouseWheel(delta);
        robot.waitForIdle();
        checkScrollPane(true);

        // vertical scroll bar is enabled + shift
        initScrollPane(true, false);
        robot.waitForIdle();
        robot.keyPress(KeyEvent.VK_SHIFT);
        robot.mouseWheel(delta);
        robot.keyRelease(KeyEvent.VK_SHIFT);
        robot.waitForIdle();
        checkScrollPane(true);

        // horizontal scroll bar is enabled
        initScrollPane(false, true);
        robot.waitForIdle();
        robot.mouseWheel(delta);
        robot.waitForIdle();
        checkScrollPane(false);

        // horizontal scroll bar is enabled + shift
        initScrollPane(false, true);
        robot.waitForIdle();
        robot.keyPress(KeyEvent.VK_SHIFT);
        robot.mouseWheel(delta);
        robot.keyRelease(KeyEvent.VK_SHIFT);
        robot.waitForIdle();
        checkScrollPane(false);

        // both scroll bars are enabled
        initScrollPane(true, true);
        robot.waitForIdle();
        robot.mouseWheel(delta);
        robot.waitForIdle();
        checkScrollPane(true);

        // both scroll bars are enabled + shift
        initScrollPane(true, true);
        robot.waitForIdle();
        robot.keyPress(KeyEvent.VK_SHIFT);
        robot.mouseWheel(delta);
        robot.keyRelease(KeyEvent.VK_SHIFT);
        robot.waitForIdle();
        checkScrollPane(false);
    }