Java Code Examples for java.awt.Frame#pack()
The following examples show how to use
java.awt.Frame#pack() .
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: WindowsLeak.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { Robot r = new Robot(); for (int i = 0; i < 100; i++) { Frame f = new Frame(); f.pack(); f.dispose(); } r.waitForIdle(); Disposer.addRecord(new Object(), () -> disposerPhantomComplete = true); while (!disposerPhantomComplete) { Util.generateOOME(); } Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>) AppContext.getAppContext().get(Window.class); if (windowList != null && !windowList.isEmpty()) { throw new RuntimeException("Test FAILED: Window list is not empty: " + windowList.size()); } System.out.println("Test PASSED"); }
Example 2
Source File: ScrollPanePreferredSize.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(final String[] args) { final Dimension expected = new Dimension(300, 300); final Frame frame = new Frame(); final ScrollPane sp = new ScrollPane(); sp.setSize(expected); frame.add(sp); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); sleep(); final Dimension size = frame.getSize(); if (size.width < expected.width || size.height < expected.height) { throw new RuntimeException( "Expected size: >= " + expected + ", actual size: " + size); } frame.dispose(); }
Example 3
Source File: FrameMinimizeTest.java From hottub with GNU General Public License v2.0 | 6 votes |
public static void main(String args[]) throws Exception { Frame frame = new Frame("Frame Minimize Test"); Button b = new Button("Focus ownder"); frame.add("South", b); frame.pack(); frame.setVisible(true); Util.waitForIdle(null); if (!b.hasFocus()) { throw new RuntimeException("button is not a focus owner after showing :("); } frame.setExtendedState(Frame.ICONIFIED); Util.waitForIdle(null); frame.setExtendedState(Frame.NORMAL); Util.waitForIdle(null); if (!b.hasFocus()) { throw new RuntimeException("button is not a focus owner after restoring :("); } }
Example 4
Source File: ScrollPanePreferredSize.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(final String[] args) { final Dimension expected = new Dimension(300, 300); final Frame frame = new Frame(); final ScrollPane sp = new ScrollPane(); sp.setSize(expected); frame.add(sp); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); sleep(); final Dimension size = frame.getSize(); if (size.width < expected.width || size.height < expected.height) { throw new RuntimeException( "Expected size: >= " + expected + ", actual size: " + size); } frame.dispose(); }
Example 5
Source File: TextAreaTwicePack.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public static void main(final String[] args) { final Frame frame = new Frame(); final TextArea ta = new TextArea(); frame.add(ta); frame.pack(); frame.setVisible(true); sleep(); final Dimension before = frame.getSize(); frame.pack(); final Dimension after = frame.getSize(); if (!after.equals(before)) { throw new RuntimeException( "Expected size: " + before + ", actual size: " + after); } frame.dispose(); }
Example 6
Source File: TextAreaTwicePack.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(final String[] args) { final Frame frame = new Frame(); final TextArea ta = new TextArea(); frame.add(ta); frame.pack(); frame.setVisible(true); sleep(); final Dimension before = frame.getSize(); frame.pack(); final Dimension after = frame.getSize(); if (!after.equals(before)) { throw new RuntimeException( "Expected size: " + before + ", actual size: " + after); } frame.dispose(); }
Example 7
Source File: AWTConsole.java From beanshell with Apache License 2.0 | 5 votes |
public static void main( String args[] ) { AWTConsole console = new AWTConsole(); final Frame f = new Frame("Bsh Console"); f.add(console, "Center"); f.pack(); f.setVisible(true); f.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { f.dispose(); } } ); interpreter = new Interpreter( console ); interpreter.run(); }
Example 8
Source File: DrawXORModeTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { final DrawXORModeTest c = new DrawXORModeTest(); final Frame f = new Frame("XOR mode test"); f.add(c); f.pack(); f.setVisible(true); try { c.checkResult(); } finally { f.dispose(); } }
Example 9
Source File: CycleThroughFrameTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public void createAndShowInstructionFrame() { Button passButton = new Button("Pass"); passButton.setEnabled(true); Button failButton = new Button("Fail"); failButton.setEnabled(true); TextArea instructions = new TextArea(12, 70); instructions.setText(TEST_INSTRUCTIONS); instructionFrame = new Frame("Test Instructions"); instructionFrame.add(passButton); instructionFrame.add(failButton); instructionFrame.add(instructions); instructionFrame.setSize(200,200); instructionFrame.setLayout(new FlowLayout()); instructionFrame.pack(); instructionFrame.setVisible(true); passButton.addActionListener(ae -> { dispose(); testContinueFlag = false; }); failButton.addActionListener(ae -> { dispose(); testContinueFlag = false; throw new RuntimeException(FAIL_MESSAGE); }); }
Example 10
Source File: SharedMemoryPixmapsTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** Creates a new instance of SharedMemoryPixmapsTest */ public SharedMemoryPixmapsTest() { testFrame = new Frame("SharedMemoryPixmapsTest"); testFrame.add(new TestComponent()); testFrame.setUndecorated(true); testFrame.setResizable(false); testFrame.pack(); testFrame.setLocationRelativeTo(null); testFrame.setVisible(true); testFrame.toFront(); }
Example 11
Source File: SharedMemoryPixmapsTest.java From hottub with GNU General Public License v2.0 | 5 votes |
/** Creates a new instance of SharedMemoryPixmapsTest */ public SharedMemoryPixmapsTest() { testFrame = new Frame("SharedMemoryPixmapsTest"); testFrame.add(new TestComponent()); testFrame.setUndecorated(true); testFrame.setResizable(false); testFrame.pack(); testFrame.setLocationRelativeTo(null); testFrame.setVisible(true); testFrame.toFront(); }
Example 12
Source File: DrawXORModeTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { final DrawXORModeTest c = new DrawXORModeTest(); final Frame f = new Frame("XOR mode test"); f.add(c); f.pack(); f.setVisible(true); try { c.checkResult(); } finally { f.dispose(); } }
Example 13
Source File: DitherTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String args[]) { Frame f = new Frame("DitherTest"); DitherTest ditherTest = new DitherTest(); ditherTest.init(); f.add("Center", ditherTest); f.pack(); f.setVisible(true); ditherTest.start(); }
Example 14
Source File: TestPrintDlgFrameAssociation.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void frameTest() { Panel panel =new Panel(); print = new Button("PrintDialog"); print.setActionCommand("PrintDialog"); print.addActionListener((e) -> { PrinterJob job = PrinterJob.getPrinterJob(); PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); t.start(); start = true; job.printDialog(aset); }); panel.add(print); frame = new Frame("Test Frame"); frame.setLayout (new BorderLayout ()); frame.add(panel,"South"); frame.pack(); frame.setVisible(true); t = new Thread (() -> { if (start) { try { Thread.sleep(5000); } catch (InterruptedException ex) {} frame.dispose(); } }); }
Example 15
Source File: DitherTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String args[]) { Frame f = new Frame("DitherTest"); DitherTest ditherTest = new DitherTest(); ditherTest.init(); f.add("Center", ditherTest); f.pack(); f.setVisible(true); ditherTest.start(); }
Example 16
Source File: Find.java From pdfxtk with Apache License 2.0 | 5 votes |
public static void main(String[] argv) { try { Proxy p = (Proxy)Class.forName(argv[1]).getConstructor(new Class[] {iiuf.db.Connection.class}).newInstance(new Object[] {new iiuf.db.fmpro.Connection(new URL(argv[0]))}); String[] fields = new String[argv.length - 2]; for(int i = 0; i < fields.length; i++) fields[i] = argv[i + 2]; find = new Find(p, Find.ENGLISH, "Field", new String[] {"AND", "OR"}, "Value", "Sorting", "Sort order:", fields); tv = new TableView(p, Proxy.AND); find.addFindListener(tv); for(int i = 0; i < fields.length; i++) tv.addColumn(fields[i]); Frame f = new Frame(); Frame f2 = new Frame(); f.add(find); f.pack(); f.setVisible(true); VNav vnav = new VNav(500); vnav.setMinimum(-20); vnav.setMaximum(20); vnav.invertValue(); f2.setLayout(new GridBagLayout()); f2.add(tv, Awt.constraints(false, GridBagConstraints.BOTH)); f2.add(vnav, Awt.constraints(true, GridBagConstraints.VERTICAL)); vnav.addAdjustmentListener(tv); f2.pack(); f2.setVisible(true); } catch(Exception e) { e.printStackTrace(); } }
Example 17
Source File: DitherTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String args[]) { Frame f = new Frame("DitherTest"); DitherTest ditherTest = new DitherTest(); ditherTest.init(); f.add("Center", ditherTest); f.pack(); f.setVisible(true); ditherTest.start(); }
Example 18
Source File: DrawImageBilinear.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) { boolean show = false; for (String arg : args) { if ("-show".equals(arg)) { show = true; } } String arch = System.getProperty("os.arch"); boolean isOglEnabled = Boolean.getBoolean("sun.java2d.opengl"); skipOglTextureTest = isOglEnabled && ("sparc".equals(arch)); System.out.println("Skip OpenGL texture test: " + skipOglTextureTest); DrawImageBilinear test = new DrawImageBilinear(); Frame frame = new Frame(); frame.add(test); frame.pack(); frame.setVisible(true); // Wait until the component's been painted synchronized (test) { while (!done) { try { test.wait(); } catch (InterruptedException e) { throw new RuntimeException("Failed: Interrupted"); } } } GraphicsConfiguration gc = frame.getGraphicsConfiguration(); if (gc.getColorModel() instanceof IndexColorModel) { System.out.println("IndexColorModel detected: " + "test considered PASSED"); frame.dispose(); return; } if (!show) { frame.dispose(); } if (capture == null) { throw new RuntimeException("Failed: capture is null"); } // Test background color int pixel = capture.getRGB(5, 5); if (pixel != 0xffffffff) { throw new RuntimeException("Failed: Incorrect color for " + "background"); } // Test pixels testRegion(capture, new Rectangle(10, 10, 40, 40)); testRegion(capture, new Rectangle(80, 10, 40, 40)); testRegion(capture, new Rectangle(150, 10, 40, 40)); }
Example 19
Source File: EmbeddedFrameGrabTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Test fails if it throws any exception. * * @throws Exception */ private void init() throws Exception { if (!System.getProperty("os.name").startsWith("Windows")) { System.out.println("This is Windows only test."); return; } final Frame frame = new Frame("AWT Frame"); frame.pack(); frame.setSize(200, 200); FramePeer frame_peer = AWTAccessor.getComponentAccessor() .getPeer(frame); Class comp_peer_class = Class.forName("sun.awt.windows.WComponentPeer"); Field hwnd_field = comp_peer_class.getDeclaredField("hwnd"); hwnd_field.setAccessible(true); long hwnd = hwnd_field.getLong(frame_peer); Class clazz = Class.forName("sun.awt.windows.WEmbeddedFrame"); Constructor constructor = clazz.getConstructor(new Class[]{long.class}); final Frame embedded_frame = (Frame) constructor.newInstance(new Object[]{ new Long(hwnd)});; final JComboBox<String> combo = new JComboBox<>(new String[]{ "Item 1", "Item 2" }); combo.setSelectedIndex(1); final Panel p = new Panel(); p.setLayout(new BorderLayout()); embedded_frame.add(p, BorderLayout.CENTER); embedded_frame.validate(); p.add(combo); p.validate(); frame.setVisible(true); Robot robot = new Robot(); robot.delay(2000); Rectangle clos = new Rectangle( combo.getLocationOnScreen(), combo.getSize()); robot.mouseMove(clos.x + clos.width / 2, clos.y + clos.height / 2); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.delay(1000); if (!combo.isPopupVisible()) { throw new RuntimeException("Combobox popup is not visible!"); } robot.mouseMove(clos.x + clos.width / 2, clos.y + clos.height + 3); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.delay(1000); if (combo.getSelectedIndex() != 0) { throw new RuntimeException("Combobox selection has not changed!"); } embedded_frame.remove(p); embedded_frame.dispose(); frame.dispose(); }
Example 20
Source File: JPEGsNotAcceleratedTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) { System.setProperty("sun.java2d.pmoffscreen", "true"); System.setProperty("sun.java2d.ddforcevram", "true"); String name = "red.jpg"; f = new Frame(); f.pack(); if (f.getGraphicsConfiguration().getColorModel().getPixelSize() < 16) { System.err.println("8-bit display mode detected, dithering issues possible, "+ "considering test passed."); f.dispose(); return; } for (String arg : args) { if (arg.equals("-write")) { writeTestImage(name); System.exit(0); } else if (arg.equals("-show")) { showRes = true; } else if (arg.equals("-low")) { lowCompression = true; name ="red_low.jpg"; System.err.println("Using low jpeg compression"); } else if (arg.equals("-help")) { usage(); } else { final String filename = arg; testsStarted++; new Thread(new Runnable() { public void run() { new JPEGsNotAcceleratedTest(filename); } }).start(); } } if (testsStarted == 0) { writeTestImage(name); testsStarted++; new JPEGsNotAcceleratedTest(name); } synchronized (JPEGsNotAcceleratedTest.class) { while (testsFinished < testsStarted) { try { JPEGsNotAcceleratedTest.class.wait(100); } catch (InterruptedException e) { failed = true; break; } } } f.dispose(); if (failed) { throw new RuntimeException("Test failed"); } System.err.println("Passed."); }