Java Code Examples for java.awt.Frame#setLocation()
The following examples show how to use
java.awt.Frame#setLocation() .
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: MultiResolutionCursorTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public void start() { //Get things going. Request focus, set size, et cetera setSize(200, 200); setVisible(true); validate(); final Image image = new MultiResolutionCursor(); int center = sizes[0] / 2; Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor( image, new Point(center, center), "multi-resolution cursor"); Frame frame = new Frame("Test Frame"); frame.setSize(300, 300); frame.setLocation(300, 50); frame.add(new Label("Move cursor here")); frame.setCursor(cursor); frame.setVisible(true); }
Example 2
Source File: MultiResolutionCursorTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public void start() { //Get things going. Request focus, set size, et cetera setSize(200, 200); setVisible(true); validate(); final Image image = new MultiResolutionCursor(); int center = sizes[0] / 2; Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor( image, new Point(center, center), "multi-resolution cursor"); Frame frame = new Frame("Test Frame"); frame.setSize(300, 300); frame.setLocation(300, 50); frame.add(new Label("Move cursor here")); frame.setCursor(cursor); frame.setVisible(true); }
Example 3
Source File: ChoicePopupLocation.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static void test(final Point tmp) throws Exception { Choice choice = new Choice(); for (int i = 1; i < 7; i++) { choice.add("Long-long-long-long-long text in the item-" + i); } Frame frame = new Frame(); try { frame.setAlwaysOnTop(true); frame.setLayout(new FlowLayout()); frame.add(choice); frame.pack(); frameWidth = frame.getWidth(); frame.setSize(frameWidth, SIZE); frame.setVisible(true); frame.setLocation(tmp.x, tmp.y); openPopup(choice); } finally { frame.dispose(); } }
Example 4
Source File: MultiResolutionCursorTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public void start() { //Get things going. Request focus, set size, et cetera setSize(200, 200); setVisible(true); validate(); final Image image = new MultiResolutionCursor(); int center = sizes[0] / 2; Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor( image, new Point(center, center), "multi-resolution cursor"); Frame frame = new Frame("Test Frame"); frame.setSize(300, 300); frame.setLocation(300, 50); frame.add(new Label("Move cursor here")); frame.setCursor(cursor); frame.setVisible(true); }
Example 5
Source File: FrameDemo.java From Java with Artistic License 2.0 | 6 votes |
public static void main(String[] args) { // ����������� Frame f = new Frame(); // ���ñ��� f.setTitle("�ٶ�һ��,���֪��"); // ���ô����С f.setSize(400, 300); // ���ô���ɼ� f.setVisible(true); // ����λ�� f.setLocation(500, 200); // f.show(); // System.out.println("over"); }
Example 6
Source File: FrameDemo2.java From Java with Artistic License 2.0 | 6 votes |
public static void main(String[] args) { // �������� Frame f = new Frame(); // ���ô������� f.setTitle("����ر�"); f.setSize(400, 200); f.setLocation(500, 250); // ע���¼� f.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); // ���ô���ɼ� f.setVisible(true); }
Example 7
Source File: TextAreaScrolling.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
TextAreaScrolling() { try { robot = new Robot(); } catch (Exception ex) { throw new RuntimeException("Robot Creation Failed"); } mainFrame = new Frame(); mainFrame.setSize(200, 200); mainFrame.setLocation(200, 200); textArea = new TextArea(); textArea.setText("1234 5678"); textArea.setSelectionStart(3); textArea.setSelectionEnd(4); mainFrame.add(textArea); mainFrame.setVisible(true); textArea.requestFocusInWindow(); }
Example 8
Source File: OptionsHandler.java From JPPF with Apache License 2.0 | 5 votes |
/** * 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 9
Source File: MissingEventsOnModalDialogTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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 10
Source File: MissingEventsOnModalDialogTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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 11
Source File: ChildWindowProperties.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void testChildPropertiesWithFrameAsParent() { parentFrame = new Frame("parent Frame"); parentFrame.setSize(WIDTH, HEIGHT); parentFrame.setLocation(100, 400); parentFrame.setBackground(Color.BLUE); parentLabel = new Label("ParentForegroundAndFont"); parentFont = new Font("Courier New", Font.ITALIC, 15); parentFrame.setForeground(Color.RED); parentFrame.setFont(parentFont); parentFrame.add(parentLabel); parentFrame.setVisible(true); frameChildWindow = new Window(parentFrame); frameChildWindow.setSize(WIDTH, HEIGHT); frameChildWindow.setLocation(WIDTH + 200, 400); childLabel = new Label("ChildForegroundAndFont"); frameChildWindow.add(childLabel); frameChildWindow.setVisible(true); if (parentFrame.getBackground() == frameChildWindow.getBackground()) { dispose(); throw new RuntimeException("Child Window Should NOT Inherit " + "Parent Frame's Background Color"); } if (parentDialog.getForeground() == windowChild.getForeground()) { dispose(); throw new RuntimeException("Child Window Should NOT Inherit " + "Parent Frame's Foreground Color"); } if (parentDialog.getFont() == windowChild.getFont()) { dispose(); throw new RuntimeException("Child Window Should NOT Inherit " + "Parent Frame's Font Color"); } }
Example 12
Source File: MultiScreenInsetsTest.java From hottub with GNU General Public License v2.0 | 4 votes |
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 13
Source File: MultiScreenLocationTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
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 14
Source File: MultiScreenInsetsTest.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
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 15
Source File: ComponentIsNotDrawnAfterRemoveAddTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
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 16
Source File: JPEGsNotAcceleratedTest.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
private static void showRes(String desc, final BufferedImage src) { final int w = src.getWidth(); final int h = src.getHeight(); Frame f = new Frame(desc+": dbl-click to exit"); Component c; f.add(c = new Component() { public Dimension getPreferredSize() { return new Dimension(w,h); } public void paint(Graphics g) { g.clearRect(0, 0, getWidth(), getHeight()); g.drawImage(src, 0,0, null); } }); c.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() > 1) { System.exit(0); } } }); f.pack(); synchronized (JPEGsNotAcceleratedTest.class) { f.setLocation(frameX, frameY); frameX += f.getWidth(); if ((frameX + f.getWidth()) > f.getGraphicsConfiguration().getBounds().width) { frameY += TEST_H; if ((frameY + f.getHeight()) > f.getGraphicsConfiguration().getBounds().height) { startY += 30; startX += 30; frameY = startY; } frameX = startX; } }; f.setVisible(true); }
Example 17
Source File: MultiScreenInsetsTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
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 18
Source File: MultiScreenInsetsTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
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 19
Source File: MultiScreenLocationTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
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 20
Source File: ComponentIsNotDrawnAfterRemoveAddTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
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); }