Java Code Examples for java.awt.Dialog#setLayout()

The following examples show how to use java.awt.Dialog#setLayout() . 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: NbPresenterLeakTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@RandomlyFails // NB-Core-Build #1189
public void testLeakingNbPresenterDescriptor () throws InterruptedException, InvocationTargetException {
    try {
        Class.forName("java.lang.AutoCloseable");
    } catch (ClassNotFoundException ex) {
        // this test is known to fail due to JDK bugs 7070542 & 7072167
        // which are unlikely to be fixed on JDK6. Thus, if AutoCloseable
        // is not present, skip the test
        return;
    }
    
    WizardDescriptor wizardDescriptor = new WizardDescriptor(getPanels(), null);
    wizardDescriptor.setModal (false);
    Dialog dialog = DialogDisplayer.getDefault ().createDialog (wizardDescriptor);
    WeakReference<WizardDescriptor> w = new WeakReference<WizardDescriptor> (wizardDescriptor);
    
    SwingUtilities.invokeAndWait (new EDTJob(dialog, true));
    assertShowing("button is visible", true, dialog);
    SwingUtilities.invokeAndWait (new EDTJob(dialog, false));
    assertShowing("button is no longer visible", false, dialog);
    boolean cancelled = wizardDescriptor.getValue() !=
        WizardDescriptor.FINISH_OPTION;
    Dialog d = new JDialog();
    
    // workaround for JDK bug 6575402
    JPanel p = new JPanel();
    d.setLayout(new BorderLayout());
    d.add(p, BorderLayout.CENTER);
    JButton btn = new JButton("Button");
    p.add(btn, BorderLayout.NORTH);
    
    SwingUtilities.invokeAndWait (new EDTJob(d, true));
    assertShowing("button is visible", true, btn);
    dialog.setBounds(Utilities.findCenterBounds(dialog.getSize()));
    SwingUtilities.invokeAndWait (new EDTJob(d, false));
    assertShowing("button is no longer visible", false, btn);

    assertNull ("BufferStrategy was disposed.", dialog.getBufferStrategy ());

    RepaintManager rm = RepaintManager.currentManager(dialog);
    rm.setDoubleBufferingEnabled(!rm.isDoubleBufferingEnabled());
    rm.setDoubleBufferingEnabled(!rm.isDoubleBufferingEnabled());
    
    dialog = null;
    wizardDescriptor = null;
    
    SwingUtilities.invokeAndWait (new Runnable() {

        @Override
        public void run() {
            Frame f = new Frame();
            f.setPreferredSize( new Dimension(100,100));
            f.setVisible( true );
            JDialog dlg = new JDialog(f);
            dlg.setVisible(true);
        }
    });

    assertGC ("Dialog disappears.", w);
}