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

The following examples show how to use javax.swing.JFrame#dispose() . 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: DrawEngineTest.java    From netbeans with Apache License 2.0 7 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 File: DrawEngineTest.java    From netbeans with 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 File: CustomComboBoxFocusTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void doStep() {
    JFrame f = getFrame();
    if (f != null) {
        f.dispose();
    }
    System.out.println("Done");

    testDone.countDown();
}
 
Example 4
Source File: WindowClosedEventOnDispose.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 5
Source File: WindowClosedEventOnDispose.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 6
Source File: WindowClosedEventOnDispose.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 7
Source File: bug8071705.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void componentShown(ComponentEvent e) {
    JFrame frame = (JFrame) e.getComponent();

    runActualTest(device, latch, frame, result);

    frame.setVisible(false);
    frame.dispose();
    latch.countDown();
}
 
Example 8
Source File: Test6541987.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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 9
Source File: DrawBitmaskToSurfaceTest.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 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 10
Source File: bug6421058.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    final JFrame mainFrame = new JFrame();
    try {
        testDefaultFont(mainFrame);
    } finally {
        mainFrame.dispose();
    }
}
 
Example 11
Source File: CustomComboBoxFocusTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void doStep() {
    JFrame f = getFrame();
    if (f != null) {
        f.dispose();
    }
    System.out.println("Done");

    testDone.countDown();
}
 
Example 12
Source File: ImageWriter.java    From SciGraph with 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 13
Source File: WindowClosedEventOnDispose.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 14
Source File: WindowClosedEventOnDispose.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 15
Source File: Test6541987.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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 16
Source File: CustomComboBoxFocusTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void doStep() {
    JFrame f = getFrame();
    if (f != null) {
        f.dispose();
    }
    System.out.println("Done");

    testDone.countDown();
}
 
Example 17
Source File: WindowClosedEventOnDispose.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 18
Source File: AnnotateScreenCapture.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
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 19
Source File: WindowClosedEventOnDispose.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 20
Source File: bug8071705.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void componentShown(ComponentEvent e) {
    JFrame frame = (JFrame) e.getComponent();

    runActualTest(device, latch, frame, result);

    frame.setVisible(false);
    frame.dispose();
    latch.countDown();
}