Java Code Examples for java.awt.Frame#setBounds()

The following examples show how to use java.awt.Frame#setBounds() . 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: DisabledUndoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void initTestWindow() {
    mainFrame = new Frame();
    p1 = new Panel();
    mainFrame.setTitle("TestWindow");
    mainFrame.setBounds(700, 10, 400, 100);

    tf = new TextField(20);
    tf.select(0, 10);
    bt = new Button("Disable textfield");
    p1.add(tf);
    p1.add(bt);
    mainFrame.add(p1);
    bt.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            tf.setEditable(false);
        }
    });
    mainFrame.setVisible(true);
}
 
Example 2
Source File: InvisibleParentTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void createAWTComponents() {
    Frame f1 = new Frame("F1");
    f1.setBounds(100, 300, 100, 100);
    f1.setVisible(true);

    try {
        Thread.sleep(500);
    } catch (Exception ex) {
    }

    f1.setExtendedState(Frame.ICONIFIED);

    Frame g1 = new Frame("G1");
    g1.setBounds(150, 350, 100, 100);
    g1.setVisible(true);

    final Dialog d1 = new Dialog((Frame) null, "D1", Dialog.ModalityType.APPLICATION_MODAL);
    d1.setBounds(200, 400, 100, 100);
    new Thread(new Runnable() {
        public void run() {
            d1.setVisible(true);
        }
    }).start();
}
 
Example 3
Source File: AltGraphModifierTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void initTestWindow() {
    mainFrame = new Frame();
    mainFrame.setTitle("TestWindow");
    mainFrame.setBounds(700, 10, 300, 300);
    mainFrame.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            int ex = e.getModifiersEx();
            if ((ex & InputEvent.ALT_GRAPH_DOWN_MASK) == 0) {
                AltGraphModifierTest.fail("Alt-Gr Modifier bit is not set.");
            } else {
                AltGraphModifierTest.pass();
            }
        }
    });
    mainFrame.setVisible(true);
}
 
Example 4
Source File: NpeOnCloseTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args)
{
    Frame frame1 = new Frame("frame 1");
    frame1.setBounds(0, 0, 100, 100);
    frame1.setVisible(true);
    Util.waitForIdle(null);

    Frame frame2 = new Frame("frame 2");
    frame2.setBounds(150, 0, 100, 100);
    frame2.setVisible(true);
    Util.waitForIdle(null);

    Frame frame3 = new Frame("frame 3");
    final Dialog dialog = new Dialog(frame3, "dialog", true);
    dialog.setBounds(300, 0, 100, 100);
    EventQueue.invokeLater(new Runnable() {
            public void run() {
                dialog.setVisible(true);
            }
        });
    try {
        EventQueue.invokeAndWait(new Runnable() { public void run() {} });
        Util.waitForIdle(null);
        EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    dialog.dispose();
                }
            });
    }
    catch (InterruptedException ie) {
        throw new RuntimeException(ie);
    }
    catch (InvocationTargetException ite) {
        throw new RuntimeException(ite);
    }

    frame1.dispose();
    frame2.dispose();
    frame3.dispose();
}
 
Example 5
Source File: DialogAboveFrameTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot robot = Util.createRobot();

    Frame frame = new Frame("Frame");
    frame.setBackground(Color.BLUE);
    frame.setBounds(200, 50, 300, 300);
    frame.setVisible(true);

    Dialog dialog1 = new Dialog(frame, "Dialog 1", false);
    dialog1.setBackground(Color.RED);
    dialog1.setBounds(100, 100, 200, 200);
    dialog1.setVisible(true);

    Dialog dialog2 = new Dialog(frame, "Dialog 2", false);
    dialog2.setBackground(Color.GREEN);
    dialog2.setBounds(400, 100, 200, 200);
    dialog2.setVisible(true);

    Util.waitForIdle(robot);

    Util.clickOnComp(dialog2, robot);
    Util.waitForIdle(robot);

    Point point = dialog1.getLocationOnScreen();
    int x = point.x + (int)(dialog1.getWidth() * 0.9);
    int y = point.y + (int)(dialog1.getHeight() * 0.9);

    try {
        if (!Util.testPixelColor(x, y, dialog1.getBackground(), 10, 100, robot)) {
            throw new RuntimeException("Test FAILED: Dialog is behind the frame");
        }
    } finally {
        frame.dispose();
        dialog1.dispose();
        dialog2.dispose();
    }
}
 
Example 6
Source File: DialogAboveFrameTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot robot = Util.createRobot();

    Frame frame = new Frame("Frame");
    frame.setBackground(Color.BLUE);
    frame.setBounds(200, 50, 300, 300);
    frame.setVisible(true);

    Dialog dialog1 = new Dialog(frame, "Dialog 1", false);
    dialog1.setBackground(Color.RED);
    dialog1.setBounds(100, 100, 200, 200);
    dialog1.setVisible(true);

    Dialog dialog2 = new Dialog(frame, "Dialog 2", false);
    dialog2.setBackground(Color.GREEN);
    dialog2.setBounds(400, 100, 200, 200);
    dialog2.setVisible(true);

    Util.waitForIdle(robot);

    Util.clickOnComp(dialog2, robot);
    Util.waitForIdle(robot);

    Point point = dialog1.getLocationOnScreen();
    int x = point.x + (int)(dialog1.getWidth() * 0.9);
    int y = point.y + (int)(dialog1.getHeight() * 0.9);

    try {
        if (!Util.testPixelColor(x, y, dialog1.getBackground(), 10, 100, robot)) {
            throw new RuntimeException("Test FAILED: Dialog is behind the frame");
        }
    } finally {
        frame.dispose();
        dialog1.dispose();
        dialog2.dispose();
    }
}
 
Example 7
Source File: NpeOnCloseTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args)
{
    Frame frame1 = new Frame("frame 1");
    frame1.setBounds(0, 0, 100, 100);
    frame1.setVisible(true);
    Util.waitForIdle(null);

    Frame frame2 = new Frame("frame 2");
    frame2.setBounds(150, 0, 100, 100);
    frame2.setVisible(true);
    Util.waitForIdle(null);

    Frame frame3 = new Frame("frame 3");
    final Dialog dialog = new Dialog(frame3, "dialog", true);
    dialog.setBounds(300, 0, 100, 100);
    EventQueue.invokeLater(new Runnable() {
            public void run() {
                dialog.setVisible(true);
            }
        });
    try {
        EventQueue.invokeAndWait(new Runnable() { public void run() {} });
        Util.waitForIdle(null);
        EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    dialog.dispose();
                }
            });
    }
    catch (InterruptedException ie) {
        throw new RuntimeException(ie);
    }
    catch (InvocationTargetException ite) {
        throw new RuntimeException(ite);
    }

    frame1.dispose();
    frame2.dispose();
    frame3.dispose();
}
 
Example 8
Source File: NpeOnCloseTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args)
{
    Frame frame1 = new Frame("frame 1");
    frame1.setBounds(0, 0, 100, 100);
    frame1.setVisible(true);
    Util.waitForIdle(null);

    Frame frame2 = new Frame("frame 2");
    frame2.setBounds(150, 0, 100, 100);
    frame2.setVisible(true);
    Util.waitForIdle(null);

    Frame frame3 = new Frame("frame 3");
    final Dialog dialog = new Dialog(frame3, "dialog", true);
    dialog.setBounds(300, 0, 100, 100);
    EventQueue.invokeLater(new Runnable() {
            public void run() {
                dialog.setVisible(true);
            }
        });
    try {
        EventQueue.invokeAndWait(new Runnable() { public void run() {} });
        Util.waitForIdle(null);
        EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    dialog.dispose();
                }
            });
    }
    catch (InterruptedException ie) {
        throw new RuntimeException(ie);
    }
    catch (InvocationTargetException ite) {
        throw new RuntimeException(ite);
    }

    frame1.dispose();
    frame2.dispose();
    frame3.dispose();
}
 
Example 9
Source File: DialogAboveFrameTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot robot = Util.createRobot();

    Frame frame = new Frame("Frame");
    frame.setBackground(Color.BLUE);
    frame.setBounds(200, 50, 300, 300);
    frame.setVisible(true);

    Dialog dialog1 = new Dialog(frame, "Dialog 1", false);
    dialog1.setBackground(Color.RED);
    dialog1.setBounds(100, 100, 200, 200);
    dialog1.setVisible(true);

    Dialog dialog2 = new Dialog(frame, "Dialog 2", false);
    dialog2.setBackground(Color.GREEN);
    dialog2.setBounds(400, 100, 200, 200);
    dialog2.setVisible(true);

    Util.waitForIdle(robot);

    Util.clickOnComp(dialog2, robot);
    Util.waitForIdle(robot);

    Point point = dialog1.getLocationOnScreen();
    int x = point.x + (int)(dialog1.getWidth() * 0.9);
    int y = point.y + (int)(dialog1.getHeight() * 0.9);

    try {
        if (!Util.testPixelColor(x, y, dialog1.getBackground(), 10, 100, robot)) {
            throw new RuntimeException("Test FAILED: Dialog is behind the frame");
        }
    } finally {
        frame.dispose();
        dialog1.dispose();
        dialog2.dispose();
    }
}
 
Example 10
Source File: MaximizedToMaximized.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

       Frame frame = new Frame();
        final Toolkit toolkit = Toolkit.getDefaultToolkit();
        final GraphicsEnvironment graphicsEnvironment =
                GraphicsEnvironment.getLocalGraphicsEnvironment();
        final GraphicsDevice graphicsDevice =
                graphicsEnvironment.getDefaultScreenDevice();

        final Dimension screenSize = toolkit.getScreenSize();
        final Insets screenInsets = toolkit.getScreenInsets(
                graphicsDevice.getDefaultConfiguration());

        final Rectangle availableScreenBounds = new Rectangle(screenSize);

        availableScreenBounds.x += screenInsets.left;
        availableScreenBounds.y += screenInsets.top;
        availableScreenBounds.width -= (screenInsets.left + screenInsets.right);
        availableScreenBounds.height -= (screenInsets.top + screenInsets.bottom);

        frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,
                availableScreenBounds.width, availableScreenBounds.height);
        frame.setVisible(true);

        Rectangle frameBounds = frame.getBounds();
        frame.setExtendedState(Frame.MAXIMIZED_BOTH);
        ((SunToolkit) toolkit).realSync();

        Rectangle maximizedFrameBounds = frame.getBounds();
        if (maximizedFrameBounds.width < frameBounds.width
                || maximizedFrameBounds.height < frameBounds.height) {
            throw new RuntimeException("Maximized frame is smaller than non maximized");
        }
    }
 
Example 11
Source File: ScrollSelectionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void initTestWindow() {
    mainFrame = new Frame("ScrollSelectionTest frame");
    mainFrame.setBounds(500, 0, 400, 200);

    textField = new TextField(40);
    textField.setText("abcdefghijklmnopqrstuvwxyz");
    mainFrame.add(textField);
    mainFrame.setLayout(new FlowLayout());
    textField.select(0, 20);
    mainFrame.setVisible(true);
}
 
Example 12
Source File: SetExtendedState.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Frame frame = new Frame("frame");
    frame.setBounds(100, 100, 200, 200);
    frame.setVisible(true);
    frame.setExtendedState(Frame.MAXIMIZED_BOTH);
    frame.setExtendedState(Frame.ICONIFIED);
    if (frame.getExtendedState() != Frame.ICONIFIED) {
        frame.dispose();
        throw new RuntimeException("Test Failed");
    }
    frame.dispose();
}
 
Example 13
Source File: MaximizedToMaximized.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

       Frame frame = new Frame();
        final Toolkit toolkit = Toolkit.getDefaultToolkit();
        final GraphicsEnvironment graphicsEnvironment =
                GraphicsEnvironment.getLocalGraphicsEnvironment();
        final GraphicsDevice graphicsDevice =
                graphicsEnvironment.getDefaultScreenDevice();

        final Dimension screenSize = toolkit.getScreenSize();
        final Insets screenInsets = toolkit.getScreenInsets(
                graphicsDevice.getDefaultConfiguration());

        final Rectangle availableScreenBounds = new Rectangle(screenSize);

        availableScreenBounds.x += screenInsets.left;
        availableScreenBounds.y += screenInsets.top;
        availableScreenBounds.width -= (screenInsets.left + screenInsets.right);
        availableScreenBounds.height -= (screenInsets.top + screenInsets.bottom);

        frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,
                availableScreenBounds.width, availableScreenBounds.height);
        frame.setVisible(true);

        Rectangle frameBounds = frame.getBounds();
        frame.setExtendedState(Frame.MAXIMIZED_BOTH);
        ((SunToolkit) toolkit).realSync();

        Rectangle maximizedFrameBounds = frame.getBounds();
        if (maximizedFrameBounds.width < frameBounds.width
                || maximizedFrameBounds.height < frameBounds.height) {
            throw new RuntimeException("Maximized frame is smaller than non maximized");
        }
    }
 
Example 14
Source File: DialogAboveFrameTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot robot = Util.createRobot();

    Frame frame = new Frame("Frame");
    frame.setBackground(Color.BLUE);
    frame.setBounds(200, 50, 300, 300);
    frame.setVisible(true);

    Dialog dialog1 = new Dialog(frame, "Dialog 1", false);
    dialog1.setBackground(Color.RED);
    dialog1.setBounds(100, 100, 200, 200);
    dialog1.setVisible(true);

    Dialog dialog2 = new Dialog(frame, "Dialog 2", false);
    dialog2.setBackground(Color.GREEN);
    dialog2.setBounds(400, 100, 200, 200);
    dialog2.setVisible(true);

    Util.waitForIdle(robot);

    Util.clickOnComp(dialog2, robot);
    Util.waitForIdle(robot);

    Point point = dialog1.getLocationOnScreen();
    int x = point.x + (int)(dialog1.getWidth() * 0.9);
    int y = point.y + (int)(dialog1.getHeight() * 0.9);

    try {
        if (!Util.testPixelColor(x, y, dialog1.getBackground(), 10, 100, robot)) {
            throw new RuntimeException("Test FAILED: Dialog is behind the frame");
        }
    } finally {
        frame.dispose();
        dialog1.dispose();
        dialog2.dispose();
    }
}
 
Example 15
Source File: NpeOnCloseTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args)
{
    Frame frame1 = new Frame("frame 1");
    frame1.setBounds(0, 0, 100, 100);
    frame1.setVisible(true);
    Util.waitForIdle(null);

    Frame frame2 = new Frame("frame 2");
    frame2.setBounds(150, 0, 100, 100);
    frame2.setVisible(true);
    Util.waitForIdle(null);

    Frame frame3 = new Frame("frame 3");
    final Dialog dialog = new Dialog(frame3, "dialog", true);
    dialog.setBounds(300, 0, 100, 100);
    EventQueue.invokeLater(new Runnable() {
            public void run() {
                dialog.setVisible(true);
            }
        });
    try {
        EventQueue.invokeAndWait(new Runnable() { public void run() {} });
        Util.waitForIdle(null);
        EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    dialog.dispose();
                }
            });
    }
    catch (InterruptedException ie) {
        throw new RuntimeException(ie);
    }
    catch (InvocationTargetException ite) {
        throw new RuntimeException(ite);
    }

    frame1.dispose();
    frame2.dispose();
    frame3.dispose();
}
 
Example 16
Source File: MaximizedToMaximized.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        Frame frame = new Frame();
        Robot robot = new Robot();
        final Toolkit toolkit = Toolkit.getDefaultToolkit();
        final GraphicsEnvironment graphicsEnvironment =
                GraphicsEnvironment.getLocalGraphicsEnvironment();
        final GraphicsDevice graphicsDevice =
                graphicsEnvironment.getDefaultScreenDevice();

        final Dimension screenSize = toolkit.getScreenSize();
        final Insets screenInsets = toolkit.getScreenInsets(
                graphicsDevice.getDefaultConfiguration());

        final Rectangle availableScreenBounds = new Rectangle(screenSize);

        availableScreenBounds.x += screenInsets.left;
        availableScreenBounds.y += screenInsets.top;
        availableScreenBounds.width -= (screenInsets.left + screenInsets.right);
        availableScreenBounds.height -= (screenInsets.top + screenInsets.bottom);

        frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,
                availableScreenBounds.width, availableScreenBounds.height);
        frame.setVisible(true);
        robot.waitForIdle();

        Rectangle frameBounds = frame.getBounds();
        frame.setExtendedState(Frame.MAXIMIZED_BOTH);
        robot.waitForIdle();

        Rectangle maximizedFrameBounds = frame.getBounds();

        frame.dispose();
        if (maximizedFrameBounds.width < frameBounds.width
                || maximizedFrameBounds.height < frameBounds.height) {
            throw new RuntimeException("Maximized frame is smaller than non maximized");
        }
    }
 
Example 17
Source File: DialogAboveFrameTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot robot = Util.createRobot();

    Frame frame = new Frame("Frame");
    frame.setBackground(Color.BLUE);
    frame.setBounds(200, 50, 300, 300);
    frame.setVisible(true);

    Dialog dialog1 = new Dialog(frame, "Dialog 1", false);
    dialog1.setBackground(Color.RED);
    dialog1.setBounds(100, 100, 200, 200);
    dialog1.setVisible(true);

    Dialog dialog2 = new Dialog(frame, "Dialog 2", false);
    dialog2.setBackground(Color.GREEN);
    dialog2.setBounds(400, 100, 200, 200);
    dialog2.setVisible(true);

    Util.waitForIdle(robot);

    Util.clickOnComp(dialog2, robot);
    Util.waitForIdle(robot);

    Point point = dialog1.getLocationOnScreen();
    int x = point.x + (int)(dialog1.getWidth() * 0.9);
    int y = point.y + (int)(dialog1.getHeight() * 0.9);

    try {
        if (!Util.testPixelColor(x, y, dialog1.getBackground(), 10, 100, robot)) {
            throw new RuntimeException("Test FAILED: Dialog is behind the frame");
        }
    } finally {
        frame.dispose();
        dialog1.dispose();
        dialog2.dispose();
    }
}
 
Example 18
Source File: ScreenInsetsTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
{
    boolean passed = true;

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gds = ge.getScreenDevices();
    for (GraphicsDevice gd : gds) {

        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        Rectangle gcBounds = gc.getBounds();
        Insets gcInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
        int left = gcInsets.left;
        int right = gcInsets.right;
        int bottom = gcInsets.bottom;
        int top = gcInsets.top;
        if (left < 0 || right < 0 || bottom < 0 || top < 0) {
            throw new RuntimeException("Negative value: " + gcInsets);
        }
        int maxW = gcBounds.width / 3;
        int maxH = gcBounds.height / 3;
        if (left > maxW || right > maxW || bottom > maxH || top > maxH) {
            throw new RuntimeException("Big value: " + gcInsets);
        }

        if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH))
        {
            // this state is used in the test - sorry
            continue;
        }

        Frame f = new Frame("Test", gc);
        f.setUndecorated(true);
        f.setBounds(gcBounds.x + 100, gcBounds.y + 100, 320, 240);
        f.setVisible(true);
        Util.waitForIdle(null);

        f.setExtendedState(Frame.MAXIMIZED_BOTH);
        Util.waitForIdle(null);

        Rectangle fBounds = f.getBounds();
        // workaround: on Windows maximized windows have negative coordinates
        if (fBounds.x < gcBounds.x)
        {
            fBounds.width -= (gcBounds.x - fBounds.x) * 2; // width is decreased
            fBounds.x = gcBounds.x;
        }
        if (fBounds.y < gcBounds.y)
        {
            fBounds.height -= (gcBounds.y - fBounds.y) * 2; // height is decreased
            fBounds.y = gcBounds.y;
        }
        Insets expected = new Insets(fBounds.y - gcBounds.y,
                                     fBounds.x - gcBounds.x,
                                     gcBounds.y + gcBounds.height - fBounds.y - fBounds.height,
                                     gcBounds.x + gcBounds.width - fBounds.x - fBounds.width);

        if (!expected.equals(gcInsets))
        {
            passed = false;
            System.err.println("Wrong insets for GraphicsConfig: " + gc);
            System.err.println("\tExpected: " + expected);
            System.err.println("\tActual: " + gcInsets);
        }

        f.dispose();
    }

    if (!passed)
    {
        throw new RuntimeException("TEST FAILED: Toolkit.getScreenInsets() returns wrong value for some screens");
    }
}
 
Example 19
Source File: ScreenInsetsTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
{
    boolean passed = true;

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gds = ge.getScreenDevices();
    for (GraphicsDevice gd : gds) {

        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        Rectangle gcBounds = gc.getBounds();
        Insets gcInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
        int left = gcInsets.left;
        int right = gcInsets.right;
        int bottom = gcInsets.bottom;
        int top = gcInsets.top;
        if (left < 0 || right < 0 || bottom < 0 || top < 0) {
            throw new RuntimeException("Negative value: " + gcInsets);
        }
        int maxW = gcBounds.width / 3;
        int maxH = gcBounds.height / 3;
        if (left > maxW || right > maxW || bottom > maxH || top > maxH) {
            throw new RuntimeException("Big value: " + gcInsets);
        }

        if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH))
        {
            // this state is used in the test - sorry
            continue;
        }

        Frame f = new Frame("Test", gc);
        f.setUndecorated(true);
        f.setBounds(gcBounds.x + 100, gcBounds.y + 100, 320, 240);
        f.setVisible(true);
        Util.waitForIdle(null);

        f.setExtendedState(Frame.MAXIMIZED_BOTH);
        Util.waitForIdle(null);

        Rectangle fBounds = f.getBounds();
        // workaround: on Windows maximized windows have negative coordinates
        if (fBounds.x < gcBounds.x)
        {
            fBounds.width -= (gcBounds.x - fBounds.x) * 2; // width is decreased
            fBounds.x = gcBounds.x;
        }
        if (fBounds.y < gcBounds.y)
        {
            fBounds.height -= (gcBounds.y - fBounds.y) * 2; // height is decreased
            fBounds.y = gcBounds.y;
        }
        Insets expected = new Insets(fBounds.y - gcBounds.y,
                                     fBounds.x - gcBounds.x,
                                     gcBounds.y + gcBounds.height - fBounds.y - fBounds.height,
                                     gcBounds.x + gcBounds.width - fBounds.x - fBounds.width);

        if (!expected.equals(gcInsets))
        {
            passed = false;
            System.err.println("Wrong insets for GraphicsConfig: " + gc);
            System.err.println("\tExpected: " + expected);
            System.err.println("\tActual: " + gcInsets);
        }

        f.dispose();
    }

    if (!passed)
    {
        throw new RuntimeException("TEST FAILED: Toolkit.getScreenInsets() returns wrong value for some screens");
    }
}
 
Example 20
Source File: Button2DragTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void run() {
    frame = new Frame();

    final DragSourceListener dragSourceListener = new DragSourceAdapter() {
        public void dragDropEnd(DragSourceDropEvent e) {
            dropSuccess = e.getDropSuccess();
            System.err.println("Drop was successful: " + dropSuccess);
        }
    };
    DragGestureListener dragGestureListener = new DragGestureListener() {
        public void dragGestureRecognized(DragGestureEvent dge) {
            dge.startDrag(null, new StringSelection("OK"), dragSourceListener);
        }
    };
    new DragSource().createDefaultDragGestureRecognizer(frame, DnDConstants.ACTION_MOVE,
                                                        dragGestureListener);

    DropTargetAdapter dropTargetListener = new DropTargetAdapter() {
        public void drop(DropTargetDropEvent dtde) {
            dtde.acceptDrop(DnDConstants.ACTION_MOVE);
            dtde.dropComplete(true);
            System.err.println("Drop");
        }
    };
    new DropTarget(frame, dropTargetListener);

    //What would normally go into main() will probably go here.
    //Use System.out.println for diagnostic messages that you want
    //to read after the test is done.
    frame.setUndecorated(true);
    frame.setBounds(100, 100, 200, 200);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    Robot robot = Util.createRobot();

    Util.waitForIdle(robot);

    Point startPoint = frame.getLocationOnScreen();
    Point endPoint = new Point(startPoint);
    startPoint.translate(50, 50);
    endPoint.translate(150, 150);

    Util.drag(robot, startPoint, endPoint, InputEvent.BUTTON2_MASK);

    Util.waitForIdle(robot);
    robot.delay(500);

    if (dropSuccess) {
        System.err.println("test passed");
    } else {
        throw new RuntimeException("test failed: drop was not successful");
    }
}