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

The following examples show how to use java.awt.Frame#setSize() . 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: MaximizedNormalBoundsUndecoratedTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
boolean doTest() {
    Dimension beforeMaximizeCalled = new Dimension(300,300);

    frame = new Frame("Test Frame");
    frame.setUndecorated(true);
    frame.setFocusable(true);
    frame.setSize(beforeMaximizeCalled);
    frame.setVisible(true);
    frame.setExtendedState(Frame.MAXIMIZED_BOTH);
    frame.setExtendedState(Frame.NORMAL);

    Dimension afterMaximizedCalled= frame.getBounds().getSize();

    frame.dispose();

    if (beforeMaximizeCalled.equals(afterMaximizedCalled)) {
        return true;
    }
    return false;
}
 
Example 2
Source File: ListRepaint.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) {
    for (int i = 0; i < 10; ++i) {
        final Frame frame = new Frame();
        frame.setSize(300, 300);
        frame.setLocationRelativeTo(null);
        ListRepaint list = new ListRepaint();
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        list.select(0);
        frame.add(list);
        frame.setVisible(true);
        sleep();
        list.test();
        frame.dispose();
    }
}
 
Example 3
Source File: SelectionAutoscrollTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
void createObjects() {
    textArea = new TextArea( bigString() );
    robot = Util.createRobot();

    Panel panel = new Panel();
    panel.setLayout( new GridLayout(3,3) );

    for( int y=0; y<3; ++y ) {
        for( int x=0; x<3; ++x ) {
            if( x==1 && y==1 ) {
                panel.add( textArea );
            } else {
                panel.add( new Panel() );
            }
        }
    }

    Frame frame = new Frame( "TextArea cursor icon test" );
    frame.setSize( 300, 300 );
    frame.add( panel );
    frame.setVisible( true );
}
 
Example 4
Source File: DeadKeySystemAssertionDialog.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
        Frame frame = new Frame();
        frame.setSize(300, 200);

        TextField textField = new TextField();
        frame.add(textField);

        frame.setVisible(true);
        toolkit.realSync();

        textField.requestFocus();
        toolkit.realSync();

        // Check that the system assertion dialog does not block Java
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        toolkit.realSync();

        frame.setVisible(false);
        frame.dispose();
    }
 
Example 5
Source File: SelectionAutoscrollTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
void createObjects() {
    textArea = new TextArea( bigString() );
    robot = Util.createRobot();

    Panel panel = new Panel();
    panel.setLayout( new GridLayout(3,3) );

    for( int y=0; y<3; ++y ) {
        for( int x=0; x<3; ++x ) {
            if( x==1 && y==1 ) {
                panel.add( textArea );
            } else {
                panel.add( new Panel() );
            }
        }
    }

    Frame frame = new Frame( "TextArea cursor icon test" );
    frame.setSize( 300, 300 );
    frame.add( panel );
    frame.setVisible( true );
}
 
Example 6
Source File: MultiResolutionSplashTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static void testFocus() throws Exception {

        System.out.println("Focus Test!");
        Robot robot = new Robot();
        robot.setAutoDelay(50);

        Frame frame = new Frame();
        frame.setSize(100, 100);
        String test = "123";
        TextField textField = new TextField(test);
        textField.selectAll();
        frame.add(textField);
        frame.setVisible(true);
        robot.waitForIdle();

        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        robot.keyPress(KeyEvent.VK_B);
        robot.keyRelease(KeyEvent.VK_B);
        robot.waitForIdle();

        frame.dispose();

        if(!textField.getText().equals("ab")){
            throw new RuntimeException("Focus is lost!");
        }
    }
 
Example 7
Source File: PaintNativeOnUpdate.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) throws AWTException {
    final Frame frame = new Frame();
    final Component label = new PaintNativeOnUpdate();
    frame.setBackground(Color.RED);
    frame.add(label);
    frame.setSize(300, 300);
    frame.setUndecorated(true);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    sleep();
    label.repaint();// first paint
    sleep();
    label.repaint();// incremental paint
    sleep();

    Robot robot = new Robot();
    robot.setAutoDelay(50);
    Point point = label.getLocationOnScreen();
    Color color = robot.getPixelColor(point.x + label.getWidth() / 2,
                                      point.y + label.getHeight() / 2);
    if (!color.equals(Color.GREEN)) {
        System.err.println("Expected color = " + Color.GREEN);
        System.err.println("Actual color = " + color);
        throw new RuntimeException();
    }
    frame.dispose();
}
 
Example 8
Source File: LabelRepaint.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) {
    for (int i = 0; i < 10; ++i) {
        final Frame frame = new Frame();
        frame.setSize(300, 300);
        frame.setLocationRelativeTo(null);
        LabelRepaint label = new LabelRepaint();
        frame.add(label);
        frame.setVisible(true);
        sleep();
        label.test();
        frame.dispose();
    }
}
 
Example 9
Source File: CardTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    Frame f = new Frame("CardTest");
    CardTest cardTest = new CardTest();
    cardTest.init();
    cardTest.start();

    f.add("Center", cardTest);
    f.setSize(300, 300);
    f.setVisible(true);
}
 
Example 10
Source File: OptionsHandler.java    From JPPF with Apache License 2.0 5 votes vote down vote up
/**
 * Load the specified frame state from the preferences store.
 * @param frame the frame for which the attributes are retrieved.
 * @param pref the preferences node from where the attributes are loaded.
 */
public static void loadFrameAttributes(final Frame frame, final Preferences pref) {
  final int x = pref.getInt("locationx", 0);
  final int y = pref.getInt("locationy", 0);
  final int width = pref.getInt("width", 600);
  final int height = pref.getInt("height", 768);
  frame.setSize(width, height);
  frame.setLocation(x, y);
  final boolean maximized = pref.getBoolean("maximized", false);
  if (maximized) frame.setExtendedState(Frame.MAXIMIZED_BOTH);
}
 
Example 11
Source File: PaintNativeOnUpdate.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) throws AWTException {
    final Frame frame = new Frame();
    final Component label = new PaintNativeOnUpdate();
    frame.setBackground(Color.RED);
    frame.add(label);
    frame.setSize(300, 300);
    frame.setUndecorated(true);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    sleep();
    label.repaint();// first paint
    sleep();
    label.repaint();// incremental paint
    sleep();

    Robot robot = new Robot();
    robot.setAutoDelay(50);
    Point point = label.getLocationOnScreen();
    Color color = robot.getPixelColor(point.x + label.getWidth() / 2,
                                      point.y + label.getHeight() / 2);
    if (!color.equals(Color.GREEN)) {
        System.err.println("Expected color = " + Color.GREEN);
        System.err.println("Actual color = " + color);
        throw new RuntimeException();
    }
    frame.dispose();
}
 
Example 12
Source File: SetEnabledPerformance.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void createAndShowGUI() {
    frame = new Frame();
    frame.setLayout(new FlowLayout(FlowLayout.CENTER, 25, 0));
    frame.setSize(600, 600);
    frame.setLocationRelativeTo(null);
    for (int i = 1; i < 10001; ++i) {
        frame.add(new JButton("Button " + i));
    }
    frame.setVisible(true);
}
 
Example 13
Source File: SelectionInvisibleTest.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();
        frame.setSize(300, 200);
        TextField textField = new TextField(TEXT + LAST_WORD, 30);
        Panel panel = new Panel(new FlowLayout());
        panel.add(textField);
        frame.add(panel);
        frame.setVisible(true);

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

        robot.waitForIdle();

        Point point = textField.getLocationOnScreen();
        int x = point.x + textField.getWidth() / 2;
        int y = point.y + textField.getHeight() / 2;
        robot.mouseMove(x, y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        robot.waitForIdle();

        robot.mousePress(InputEvent.BUTTON1_MASK);
        int N = 10;
        int dx = textField.getWidth() / N;
        for (int i = 0; i < N; i++) {
            x += dx;
            robot.mouseMove(x, y);
        }
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        robot.waitForIdle();

        if (!textField.getSelectedText().endsWith(LAST_WORD)) {
            throw new RuntimeException("Last word is not selected!");
        }
    }
 
Example 14
Source File: MissingEventsOnModalDialogTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static Frame createFrame(String title, int x, int y) {
    Frame frame = new Frame();
    frame.setSize(200, 200);
    frame.setLocation(x, y);
    frame.setTitle(title);
    frame.setVisible(true);
    return frame;
}
 
Example 15
Source File: CardTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    Frame f = new Frame("CardTest");
    CardTest cardTest = new CardTest();
    cardTest.init();
    cardTest.start();

    f.add("Center", cardTest);
    f.setSize(300, 300);
    f.setVisible(true);
}
 
Example 16
Source File: MultiScreenInsetsTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
    OSInfo.OSType type = OSInfo.getOSType();
    if (type != OSInfo.OSType.LINUX && type != OSInfo.OSType.SOLARIS) {
        System.out.println("This test is for Solaris and Linux only..." +
                           "skipping!");
        return;
    }

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gds = ge.getScreenDevices();
    if (gds.length < 2) {
        System.out.println("It's a multi-screen test... skipping!");
        return;
    }

    for (int screen = 0; screen < gds.length; ++screen) {
        GraphicsDevice gd = gds[screen];
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        Rectangle bounds = gc.getBounds();
        Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);

        Frame frame = new Frame(gc);
        frame.setLocation(bounds.x + (bounds.width - SIZE) / 2,
                          bounds.y + (bounds.height - SIZE) / 2);
        frame.setSize(SIZE, SIZE);
        frame.setUndecorated(true);
        frame.setVisible(true);

        // Maximize Frame to reach the struts
        frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
        Thread.sleep(2000);

        Rectangle frameBounds = frame.getBounds();
        frame.dispose();
        if (bounds.x + insets.left != frameBounds.x
            || bounds.y + insets.top != frameBounds.y
            || bounds.width - insets.right - insets.left != frameBounds.width
            || bounds.height - insets.bottom - insets.top != frameBounds.height) {
            throw new RuntimeException("Test FAILED! Wrong screen #" +
                                       screen + " insets: " + insets);
        }
    }
    System.out.println("Test PASSED!");
}
 
Example 17
Source File: MultiScreenLocationTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws AWTException
{
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gds = ge.getScreenDevices();
    if (gds.length < 2) {
        System.out.println("It's a multiscreen test... skipping!");
        return;
    }

    for (int i = 0; i < gds.length; ++i) {
        GraphicsDevice gd = gds[i];
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        Rectangle screen = gc.getBounds();
        Robot robot = new Robot(gd);

        // check Robot.mouseMove()
        robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y);
        Point mouse = MouseInfo.getPointerInfo().getLocation();
        Point point = screen.getLocation();
        point.translate(mouseOffset.x, mouseOffset.y);
        if (!point.equals(mouse)) {
            throw new RuntimeException(getErrorText("Robot.mouseMove", i));
        }

        // check Robot.getPixelColor()
        Frame frame = new Frame(gc);
        frame.setUndecorated(true);
        frame.setSize(100, 100);
        frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y);
        frame.setBackground(color);
        frame.setVisible(true);
        robot.waitForIdle();
        Rectangle bounds = frame.getBounds();
        if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) {
            throw new RuntimeException(getErrorText("Robot.getPixelColor", i));
        }

        // check Robot.createScreenCapture()
        BufferedImage image = robot.createScreenCapture(bounds);
        int rgb = color.getRGB();
        if (image.getRGB(0, 0) != rgb
            || image.getRGB(image.getWidth() - 1, 0) != rgb
            || image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb
            || image.getRGB(0, image.getHeight() - 1) != rgb) {
                throw new RuntimeException(
                        getErrorText("Robot.createScreenCapture", i));
        }
        frame.dispose();
    }

    System.out.println("Test PASSED!");
}
 
Example 18
Source File: ComponentIsNotDrawnAfterRemoveAddTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public ComponentIsNotDrawnAfterRemoveAddTest() {
    frame = new Frame("ComponentIsNotDrawnAfterRemoveAddTest");
    frame.setSize(500, 500);
    frame.setLocation(200, 200);
    frame.setLayout(null);
    frame.setBackground(Color.RED);

    panel = new Panel();
    panel.setLayout(null);
    panel.setBounds(25, 100, 455, 295);
    panel.setBackground(Color.GREEN);

    for (int i = 0; i < 10; i++) {
        TestCanvas canv1 = new TestCanvas();
        canv1.setBounds(i * 45 + 5, 15, 30 + i, 30 + i);
        panel.add(canv1);
        compList.add(canv1);

        TestButton btn1 = new TestButton();
        btn1.setBounds(i * 45 + 5, 60, 30 + i, 30 + i);
        panel.add(btn1);
        compList.add(btn1);

        TestCanvas canv2 = new TestCanvas();
        canv2.setBounds(i * 45 + 5, 105, 30 + i, 30 + i);
        panel.add(canv2);
        compList.add(canv2);

        TestButton btn2 = new TestButton();
        btn2.setBounds(i * 45 + 5, 150, 30 + i, 30 + i);
        panel.add(btn2);
        compList.add(btn2);

        TestCanvas canv3 = new TestCanvas();
        canv3.setBounds(i * 45 + 5, 195, 30 + i, 30 + i);
        panel.add(canv3);
        compList.add(canv3);

        TestButton btn3 = new TestButton();
        btn3.setBounds(i * 45 + 5, 240, 30 + i, 30 + i);
        panel.add(btn3);
        compList.add(btn3);
    }

    frame.add(panel);
    frame.setVisible(true);
}
 
Example 19
Source File: ComponentIsNotDrawnAfterRemoveAddTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public ComponentIsNotDrawnAfterRemoveAddTest() {
    frame = new Frame("ComponentIsNotDrawnAfterRemoveAddTest");
    frame.setSize(500, 500);
    frame.setLocation(200, 200);
    frame.setLayout(null);
    frame.setBackground(Color.RED);

    panel = new Panel();
    panel.setLayout(null);
    panel.setBounds(25, 100, 455, 295);
    panel.setBackground(Color.GREEN);

    for (int i = 0; i < 10; i++) {
        TestCanvas canv1 = new TestCanvas();
        canv1.setBounds(i * 45 + 5, 15, 30 + i, 30 + i);
        panel.add(canv1);
        compList.add(canv1);

        TestButton btn1 = new TestButton();
        btn1.setBounds(i * 45 + 5, 60, 30 + i, 30 + i);
        panel.add(btn1);
        compList.add(btn1);

        TestCanvas canv2 = new TestCanvas();
        canv2.setBounds(i * 45 + 5, 105, 30 + i, 30 + i);
        panel.add(canv2);
        compList.add(canv2);

        TestButton btn2 = new TestButton();
        btn2.setBounds(i * 45 + 5, 150, 30 + i, 30 + i);
        panel.add(btn2);
        compList.add(btn2);

        TestCanvas canv3 = new TestCanvas();
        canv3.setBounds(i * 45 + 5, 195, 30 + i, 30 + i);
        panel.add(canv3);
        compList.add(canv3);

        TestButton btn3 = new TestButton();
        btn3.setBounds(i * 45 + 5, 240, 30 + i, 30 + i);
        panel.add(btn3);
        compList.add(btn3);
    }

    frame.add(panel);
    frame.setVisible(true);
}
 
Example 20
Source File: MultiScreenLocationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws AWTException
{
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gds = ge.getScreenDevices();
    if (gds.length < 2) {
        System.out.println("It's a multiscreen test... skipping!");
        return;
    }

    for (int i = 0; i < gds.length; ++i) {
        GraphicsDevice gd = gds[i];
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        Rectangle screen = gc.getBounds();
        Robot robot = new Robot(gd);

        // check Robot.mouseMove()
        robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y);
        Point mouse = MouseInfo.getPointerInfo().getLocation();
        Point point = screen.getLocation();
        point.translate(mouseOffset.x, mouseOffset.y);
        if (!point.equals(mouse)) {
            throw new RuntimeException(getErrorText("Robot.mouseMove", i));
        }

        // check Robot.getPixelColor()
        Frame frame = new Frame(gc);
        frame.setUndecorated(true);
        frame.setSize(100, 100);
        frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y);
        frame.setBackground(color);
        frame.setVisible(true);
        robot.waitForIdle();
        Rectangle bounds = frame.getBounds();
        if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) {
            throw new RuntimeException(getErrorText("Robot.getPixelColor", i));
        }

        // check Robot.createScreenCapture()
        BufferedImage image = robot.createScreenCapture(bounds);
        int rgb = color.getRGB();
        if (image.getRGB(0, 0) != rgb
            || image.getRGB(image.getWidth() - 1, 0) != rgb
            || image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb
            || image.getRGB(0, image.getHeight() - 1) != rgb) {
                throw new RuntimeException(
                        getErrorText("Robot.createScreenCapture", i));
        }
        frame.dispose();
    }

    System.out.println("Test PASSED!");
}