Java Code Examples for javax.swing.JFrame#dispose()

The following examples show how to use javax.swing.JFrame#dispose() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: netbeans   File: DrawEngineTest.java    License: Apache License 2.0 6 votes vote down vote up
@RandomlyFails
public void testModelToViewCorrectness() throws Throwable {
    for(String text : TEXTS) {
        JEditorPane jep = createJep(text);
        try {
            checkModelToViewCorrectness(jep);
        } catch (Throwable e) {
            System.err.println("testModelToViewCorrectness processing {");
            System.err.println(text);
            System.err.println("} failed with:");
            e.printStackTrace();
            throw e;
        } finally {
            JFrame frame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, jep);
            if (frame != null) {
                frame.dispose();
            }
        }
    }
}
 
Example 2
Source Project: netbeans   File: DrawEngineTest.java    License: Apache License 2.0 6 votes vote down vote up
@RandomlyFails
public void testModelToViewConsistency() throws Throwable {
    for(String text : TEXTS) {
        JEditorPane jep = createJep(text);
        try {
            checkModelToViewConsistency(jep);
        } catch (Throwable e) {
            System.err.println("testModelToViewConsistency processing {");
            System.err.println(text);
            System.err.println("} failed with:");
            e.printStackTrace();
            throw e;
        } finally {
            JFrame frame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, jep);
            if (frame != null) {
                frame.dispose();
            }
        }
    }
}
 
Example 3
Source Project: SciGraph   File: ImageWriter.java    License: Apache License 2.0 5 votes vote down vote up
private static BufferedImage renderImage(JPanel panel) {
  JFrame frame = new JFrame();
  frame.setUndecorated(true);
  frame.getContentPane().add(panel);
  frame.pack();
  BufferedImage bi = new BufferedImage(panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_ARGB);
  Graphics2D graphics = bi.createGraphics();
  panel.print(graphics);
  graphics.dispose();
  frame.dispose();
  return bi;
}
 
Example 4
@Override
public void componentShown(ComponentEvent e) {
    JFrame frame = (JFrame) e.getComponent();

    runActualTest(device, latch, frame, result);

    frame.setVisible(false);
    frame.dispose();
    latch.countDown();
}
 
Example 5
/**
 * Test if a dialog that has never been shown fire
 * the WINDOW_CLOSED event on parent dispose().
 * @throws Exception
 */
public static void testHidenChildDispose() throws Exception {
    JFrame f = new JFrame();
    JDialog dlg = new JDialog(f);
    Listener l = new Listener();
    dlg.addWindowListener(l);
    f.dispose();
    waitEvents();

    assertEquals(0, l.getCount());
}
 
Example 6
public File saveToFile(File captureFile) throws FileNotFoundException, IOException {
    writePNG(captureFile);

    ImageReader reader = getPNGImageReader();
    ImageInputStream iis = ImageIO.createImageInputStream(new FileInputStream(captureFile));
    reader.setInput(iis);
    BufferedImage pngImage = reader.read(0);
    IIOMetadata imageMetadata = reader.getImageMetadata(0);

    Node root = imageMetadata.getAsTree(imageMetadata.getNativeMetadataFormatName());
    IIOMetadataNode textNode = new IIOMetadataNode("tEXt");
    ArrayList<Annotation> annotations = imagePanel.getAnnotations();
    for (int i = 0; i < annotations.size(); i++) {
        textNode.appendChild(getAnnotationNode((Annotation) annotations.get(i), i));
    }
    root.appendChild(textNode);

    imageMetadata.mergeTree(imageMetadata.getNativeMetadataFormatName(), root);

    IIOImage imageWrite = new IIOImage(pngImage, new ArrayList<BufferedImage>(), imageMetadata);

    ImageWriter writer = getPNGImageWriter();
    ImageOutputStream ios = ImageIO.createImageOutputStream(new FileOutputStream(captureFile));
    writer.setOutput(ios);
    writer.write(imageWrite);
    writer.dispose();

    JFrame frame = new JFrame();
    frame.setLayout(new BorderLayout());
    ImagePanel finalImage = new ImagePanel(new FileInputStream(captureFile), false);
    frame.add(finalImage, BorderLayout.CENTER);
    frame.pack();
    File savedFile = new File(captureFile.getParentFile(), "ext-" + captureFile.getName());
    getScreenShot(frame.getContentPane(), savedFile);
    frame.dispose();

    return savedFile;
}
 
Example 7
/**
 * Test if a dialog fire the WINDOW_CLOSED event
 * on parent dispose().
 * @throws Exception
 */
public static void testVisibleChildParentDispose() throws Exception {
    JFrame f = new JFrame();
    JDialog dlg = new JDialog(f);
    Listener l = new Listener();
    dlg.addWindowListener(l);
    dlg.setVisible(true);
    f.dispose();
    waitEvents();

    assertEquals(1, l.getCount());
}
 
Example 8
public void doStep() {
    JFrame f = getFrame();
    if (f != null) {
        f.dispose();
    }
    System.out.println("Done");

    testDone.countDown();
}
 
Example 9
public void run() {
    String title = getClass().getName();
    JFrame frame = new JFrame(title);
    frame.setVisible(true);

    Color color = JColorChooser.showDialog(frame, title, Color.BLACK);
    if (color != null) {
        throw new Error("unexpected color: " + color);
    }
    frame.setVisible(false);
    frame.dispose();
}
 
Example 10
/**
 * Test if a dialog fire the WINDOW_CLOSED event
 * on parent dispose().
 * @throws Exception
 */
public static void testVisibleChildParentDispose() throws Exception {
    JFrame f = new JFrame();
    JDialog dlg = new JDialog(f);
    Listener l = new Listener();
    dlg.addWindowListener(l);
    dlg.setVisible(true);
    f.dispose();
    waitEvents();

    assertEquals(1, l.getCount());
}
 
Example 11
/**
 * Test if a Window that has never been shown fire the
 * WINDOW_CLOSED event on dispose()
 */
public static void testHidenWindowDispose() throws Exception {
    JFrame f = new JFrame();
    Listener l = new Listener();
    f.addWindowListener(l);
    f.dispose();
    waitEvents();

    assertEquals(0, l.getCount());
}
 
Example 12
public void doStep() {
    JFrame f = getFrame();
    if (f != null) {
        f.dispose();
    }
    System.out.println("Done");

    testDone.countDown();
}
 
Example 13
public void doStep() {
    JFrame f = getFrame();
    if (f != null) {
        f.dispose();
    }
    System.out.println("Done");

    testDone.countDown();
}
 
Example 14
@Override
public void run() {
    final JFrame mainFrame = new JFrame();
    try {
        testDefaultFont(mainFrame);
    } finally {
        mainFrame.dispose();
    }
}
 
Example 15
public static void main(final String[] args) throws Exception {
    final JFrame frame = new DrawBitmaskToSurfaceTest();
    frame.setBounds(10, 350, 200, 200);
    frame.setVisible(true);

    Thread.sleep(2000);

    System.err.println("Change frame bounds...");
    latch = new CountDownLatch(1);
    frame.setBounds(10, 350, 90, 90);
    frame.repaint();

    try {
        if (latch.getCount() > 0) {
            latch.await();
        }
    } catch (InterruptedException e) {
    }

    frame.dispose();

    if (theError != null) {
        throw new RuntimeException("Test failed.", theError);
    }

    System.err.println("Test passed");
}
 
Example 16
public void run() {
    String title = getClass().getName();
    JFrame frame = new JFrame(title);
    frame.setVisible(true);

    Color color = JColorChooser.showDialog(frame, title, Color.BLACK);
    if (color != null) {
        throw new Error("unexpected color: " + color);
    }
    frame.setVisible(false);
    frame.dispose();
}
 
Example 17
@Override
public void componentShown(ComponentEvent e) {
    JFrame frame = (JFrame) e.getComponent();

    runActualTest(device, latch, frame, result);

    frame.setVisible(false);
    frame.dispose();
    latch.countDown();
}
 
Example 18
/**
 * Test if a Window that has never been shown fire the
 * WINDOW_CLOSED event on dispose()
 */
public static void testHidenWindowDispose() throws Exception {
    JFrame f = new JFrame();
    Listener l = new Listener();
    f.addWindowListener(l);
    f.dispose();
    waitEvents();

    assertEquals(0, l.getCount());
}
 
Example 19
/**
 * Test if a dialog fire the WINDOW_CLOSED event
 * on parent dispose().
 * @throws Exception
 */
public static void testVisibleChildParentDispose() throws Exception {
    JFrame f = new JFrame();
    JDialog dlg = new JDialog(f);
    Listener l = new Listener();
    dlg.addWindowListener(l);
    dlg.setVisible(true);
    f.dispose();
    waitEvents();

    assertEquals(1, l.getCount());
}
 
Example 20
/**
 * Test if a dialog that has never been shown fire
 * the WINDOW_CLOSED event on parent dispose().
 * @throws Exception
 */
public static void testHidenChildDispose() throws Exception {
    JFrame f = new JFrame();
    JDialog dlg = new JDialog(f);
    Listener l = new Listener();
    dlg.addWindowListener(l);
    f.dispose();
    waitEvents();

    assertEquals(0, l.getCount());
}