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

The following are Jave code examples for showing how to use dispose() of the javax.swing.JFrame class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: SE2017-Team1   File: TestUtil.java   View Source Code Vote up 9 votes
public static void drawAndSave(JPanel graphDrawing, String fileName) {
    JFrame frame = new JFrame("Drawing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(graphDrawing);
    frame.setSize(500, 500);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    exportToImage("jpg", graphDrawing, fileName);
    frame.dispose();
}
 
Example 2
Project: incubator-netbeans   File: NewObjectPanelTest.java   View Source Code Vote up 6 votes
public void testNewObjectPanelTest() {
    NewObjectPanel panel = new NewObjectPanel();
    JFrame frame = new JFrame("sss");
    
    frame.getContentPane().add(panel, java.awt.BorderLayout.CENTER);
    frame.pack();
    frame.setVisible(true);
    assertNotNull(panel.getNewObjectName());
    assertNotNull(panel.getPreferredSize());
    MyChangeListener list = new MyChangeListener();
    panel.addChangeListener(list);
    panel.removeChangeListener(list);
    panel.addNotify();
    assertNotNull(panel.defaultNewObjectName());
    frame.dispose();
    
}
 
Example 3
Project: dracoon-dropzone   File: Dropzone.java   View Source Code Vote up 6 votes
/**
 * Show password dialog if enabled
 */
private String showPasswordDialog() {
	JPanel panel = new JPanel(new BorderLayout());
	JPasswordField pf = new JPasswordField();
	panel.setBorder(new EmptyBorder(0, 10, 0, 10));
	panel.add(pf, BorderLayout.NORTH);
	JFrame frame = new JFrame();
	frame.setAlwaysOnTop(true);
	pf.requestFocus();

	int option = JOptionPane.showConfirmDialog(frame, panel, I18n.get("main.start.sharelinkpwd"),
			JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
	frame.dispose();
	if (option == JOptionPane.OK_OPTION) {
		return new String(pf.getPassword());
	} else {
		return null;
	}
}
 
Example 4
Project: JavaGraph   File: DisplaysPanel.java   View Source Code Vote up 6 votes
/**
 * If the component is not shown on a tab but in a separate frame,
 * disposes the frame.
 */
@Override
public void remove(Component component) {
    if (indexOfComponent(component) < 0) {
        JFrame frame = getFrameOf(component);
        if (frame != null) {
            frame.dispose();
        }
        DisplayKind kind = ((Display) component).getKind();
        this.detachedMap.remove(kind);
    } else {
        if (getSelectedComponent() == component) {
            revertSelection();
        }
        super.remove(component);
    }
}
 
Example 5
Project: openjdk-jdk10   File: _AppMenuBarHandler.java   View Source Code Vote up 6 votes
void setDefaultMenuBar(final JMenuBar menuBar) {
    installDefaultMenuBar(menuBar);

    // scan the current frames, and see if any are foreground
    final Frame[] frames = Frame.getFrames();
    for (final Frame frame : frames) {
        if (frame.isVisible() && !isFrameMinimized(frame)) {
            return;
        }
    }

    // if we have no foreground frames, then we have to "kick" the menubar
    final JFrame pingFrame = new JFrame();
    pingFrame.getRootPane().putClientProperty("Window.alpha", Float.valueOf(0.0f));
    pingFrame.setUndecorated(true);
    pingFrame.setVisible(true);
    pingFrame.toFront();
    pingFrame.setVisible(false);
    pingFrame.dispose();
}
 
Example 6
Project: openjdk-jdk10   File: SilenceOfDeprecatedMenuBar.java   View Source Code Vote up 6 votes
@Override
public void run() {
    final JFrame frame = new DeprecatedFrame();
    try {
        final JMenuBar bar = new JMenuBar();
        frame.setJMenuBar(bar);
        frame.setBounds(100, 100, 100, 100);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        if (bar != frame.getJMenuBar()) {
            throw new RuntimeException("Wrong JMenuBar");
        }
    } finally {
        frame.dispose();
    }
}
 
Example 7
Project: openjdk-jdk10   File: EditPad.java   View Source Code Vote up 6 votes
@Override
public void run() {
    JFrame jframe = new JFrame(windowLabel == null
            ? getResourceString("editpad.name")
            : windowLabel);
    Runnable closer = () -> {
        jframe.setVisible(false);
        jframe.dispose();
        closeMark.run();
    };
    jframe.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            closer.run();
        }
    });
    jframe.setLocationRelativeTo(null);
    jframe.setLayout(new BorderLayout());
    JTextArea textArea = new JTextArea(initialText);
    textArea.setFont(new Font("monospaced", Font.PLAIN, 13));
    jframe.add(new JScrollPane(textArea), BorderLayout.CENTER);
    jframe.add(buttons(closer, textArea), BorderLayout.SOUTH);

    jframe.setSize(800, 600);
    jframe.setVisible(true);
}
 
Example 8
Project: SE2017-Team1   File: TestUtil.java   View Source Code Vote up 5 votes
public static void drawAndSave(JPanel graphDrawing, String fileName, int canvasSize) {
	JFrame frame = new JFrame("Drawing");
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.add(graphDrawing);
	frame.setSize(canvasSize, canvasSize);
	frame.setLocationRelativeTo(null);
	frame.setVisible(true);
	exportToImage("jpg", graphDrawing, fileName);
	frame.dispose();
}
 
Example 9
Project: openjdk-jdk10   File: bug6421058.java   View Source Code Vote up 5 votes
@Override
public void run() {
    final JFrame mainFrame = new JFrame();
    try {
        testDefaultFont(mainFrame);
    } finally {
        mainFrame.dispose();
    }
}
 
Example 10
Project: jdk8u-jdk   File: Test6541987.java   View Source Code Vote up 5 votes
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 11
Project: openjdk-jdk10   File: WindowClosedEventOnDispose.java   View Source Code Vote up 5 votes
/**
 * 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 12
Project: openjdk-jdk10   File: Test6541987.java   View Source Code Vote up 5 votes
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 13
Project: openjdk-jdk10   File: DrawBitmaskToSurfaceTest.java   View Source Code Vote up 5 votes
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 14
Project: openjdk-jdk10   File: CustomComboBoxFocusTest.java   View Source Code Vote up 5 votes
public void doStep() {
    JFrame f = getFrame();
    if (f != null) {
        f.dispose();
    }
    System.out.println("Done");

    testDone.countDown();
}
 
Example 15
Project: SE2017-Team1   File: TestUtil.java   View Source Code Vote up 5 votes
public static void drawAndSave(JPanel graphDrawing, String fileName) {
    JFrame frame = new JFrame("Drawing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(graphDrawing);
    frame.setSize(500, 500);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    exportToImage("jpg", graphDrawing, fileName);
    frame.dispose();
}
 
Example 16
Project: openjdk-jdk10   File: bug6921687.java   View Source Code Vote up 5 votes
public static void main(String[] args) throws Exception {
    if (!Platform.isWindows()) {
        System.out.println("Only Windows platform test. Test is skipped.");
        System.out.println("ok");
        return;
    }
    final String lafClassName = UIManager.getSystemLookAndFeelClassName();
    lafClass  = Class.forName(lafClassName);
    UIManager.setLookAndFeel(lafClassName);
    try {
        SwingUtilities.invokeAndWait(() -> {
            frame = new JFrame();
            frame.setUndecorated(true);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setup(frame);
        });

        final Robot robot = new Robot();
        robot.waitForIdle();
        robot.setAutoDelay(20);
        robot.keyPress(KeyEvent.VK_ALT);
        robot.keyPress(KeyEvent.VK_F);
        robot.keyRelease(KeyEvent.VK_F);
        robot.keyRelease(KeyEvent.VK_ALT);
        robot.waitForIdle();
        checkMnemonics();

        robot.keyPress(KeyEvent.VK_ALT);
        robot.keyPress(KeyEvent.VK_S);
        robot.keyRelease(KeyEvent.VK_S);
        robot.keyRelease(KeyEvent.VK_ALT);
        robot.waitForIdle();
        checkMnemonics();
        System.out.println("ok");
    } finally {
        if (frame != null) { frame.dispose(); }
    }

}
 
Example 17
Project: openjdk-jdk10   File: WindowClosedEventOnDispose.java   View Source Code Vote up 5 votes
/**
 * 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 18
Project: jdk8u-jdk   File: DrawBitmaskToSurfaceTest.java   View Source Code Vote up 5 votes
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 19
Project: jdk8u-jdk   File: MisplacedBorder.java   View Source Code Vote up 5 votes
@Override
public void run() {
    final JMenuBar menubar = new JMenuBar();
    menubar.add(new JMenu(""));
    menubar.add(new JMenu(""));
    final JFrame frame = new JFrame();
    frame.setUndecorated(true);
    frame.setJMenuBar(menubar);
    frame.setSize(W / 3, H / 3);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    // draw menu bar using standard order.
    final BufferedImage bi1 = step1(menubar);

    // draw menu border on top of the menu bar, nothing should be changed.
    final BufferedImage bi2 = step2(menubar);
    frame.dispose();

    for (int x = 0; x < W; ++x) {
        for (int y = 0; y < H; ++y) {
            if (bi1.getRGB(x, y) != bi2.getRGB(x, y)) {
                try {
                    ImageIO.write(bi1, "png", new File("image1.png"));
                    ImageIO.write(bi2, "png", new File("image2.png"));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                throw new RuntimeException("Failed: wrong color");
            }
        }
    }
}
 
Example 20
Project: dracoon-dropzone   File: TrayPopupMenu.java   View Source Code Vote up 4 votes
@Override
public void actionPerformed(ActionEvent e) {
	if (e.getSource() == itemExit) {
		System.exit(0);
	} else if (e.getSource() == itemSettings) {
		SettingsDialog dialog = new SettingsDialog();
		JFrame frame = new JFrame();
		frame.setAlwaysOnTop(true);
		int result = JOptionPane.showConfirmDialog(frame, dialog, I18n.get("tray.settings"),
				JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
		frame.dispose();
		
		if (result == JOptionPane.OK_OPTION) {

			String username = dialog.getUserName().getText();
			String serverUrl = dialog.getServerUrl().getText();
			String storagePath = dialog.getStoragePath().getText();
			String password = new String(dialog.getPassword().getPassword());
			String masterPassword = new String(dialog.getMasterPwd().getPassword());
			boolean isMasterPwdEnabled = dialog.isMasterPwdEnabled();
			boolean isUseDarkIcon = dialog.isUseDarkIcon();

			ScreenModel screenModel = dialog.getSelectedScreen();
			ScreenPosition screenPos = dialog.getSelectedScreenPosition();
			AuthModel authMethod = dialog.getSelectedAuthMethod();

			ConfigIO cfg = ConfigIO.getInstance();
			cfg.setUsername(username);
			
			// important: first set masterpwd
			// and masterpwd enabled before
			// setting the pwd
			cfg.setMasterPwdEnabled(isMasterPwdEnabled);
			cfg.setMasterPassword(masterPassword);
			cfg.setPassword(password);
			cfg.setServerUrl(serverUrl);
			cfg.setStoragePath(storagePath);
			cfg.setScreenId(screenModel.getIdString());
			cfg.setAuthMethod(authMethod.getType().getId());
			cfg.setScreenPositionId(String.valueOf(screenPos.getPos().getId()));
			cfg.setUseDarkIcon(isUseDarkIcon);
			cfg.save();
		}
	}

}