Example usage for java.awt Window dispose

List of usage examples for java.awt Window dispose

Introduction

In this page you can find the example usage for java.awt Window dispose.

Prototype

public void dispose() 

Source Link

Document

Releases all of the native screen resources used by this Window , its subcomponents, and all of its owned children.

Usage

From source file:Main.java

public static void close(Window win) {
    if (win != null) {
        win.setVisible(false);//from   w ww  .j ava 2 s . c o m
        win.dispose();
    }
}

From source file:Main.java

public static void disposeParentWindow(JComponent component) {
    Window window = SwingUtilities.windowForComponent(component);
    if (window != null)
        window.dispose();
}

From source file:Main.java

/**
 * Close the parent window./* w  w  w. j  av  a  2s .  c  om*/
 * @see Window#dispose()
 * @param component
 */
public static void disposeWindow(Component component) {

    if (component == null) {
        return;
    }

    Window window = getParent(component, Window.class);
    if (window == null) {
        return;
    }

    window.dispose();
}

From source file:Main.java

/** Create an action to invoke {@link Window#dispose} on the given window */
public static ActionListener disposeAction(final Window w) {
    return new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            w.dispose();
        }/*  w  ww. j a  va  2s. co  m*/
    };
}

From source file:Main.java

/**
 * Attaches a {@link WindowListener} to the given Window so it is disposed
 * when the close button is hit. Some windows do not respond to the
 * DISPOSE_ON_CLOSE operation, so this is better than using that.
 *//* w w w  .ja va 2s. co m*/
public static void attachDisposeOnClose(final Window w) {
    w.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            w.setVisible(false);
            w.dispose();
        }
    });
}

From source file:Main.java

/**
 * Closes and disposes a given {@link Window}.
 * /*from   w  ww . j av  a2s.co  m*/
 * @param aWindow
 *          the window to close, if <code>null</code>, this method doesn't do
 *          anything.
 */
public static void dispose(final Window aWindow) {
    if (aWindow == null) {
        return;
    }
    if (aWindow.isVisible()) {
        aWindow.setVisible(false);
    }
    aWindow.dispose();
}

From source file:Main.java

public static void showWindow(final Window window, boolean modal) {
    Runnable r = new Runnable() {
        public void run() {
            window.pack();//from ww w  .  ja  v  a  2s  .c o m
            window.setVisible(true);
        }
    };

    if (modal) {
        try {
            SwingUtilities.invokeAndWait(r);
            window.dispose();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else {
        SwingUtilities.invokeLater(r);
    }
}

From source file:de.codesourcery.eve.skills.ui.frames.WindowManager.java

/**
 * Shutdown this window manager.//from   w  ww .  j  av  a  2 s .c  om
 * 
 * All registered windows will be closed
 * by this method.
 *  
 * @param force
 */
public void shutdown(boolean force) {

    synchronized (windows) {
        Collection<Window> frames = new ArrayList<Window>(windows.values());
        for (Window f : frames) {
            f.dispose();
        }
    }
}

From source file:misc.TextBatchPrintingDemo.java

/**
 * Create and display the main application frame.
 *///from   ww w.  j a va2 s. c om
void createAndShowGUI() {
    messageArea = new JLabel(defaultMessage);

    selectedPages = new JList(new DefaultListModel());
    selectedPages.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    selectedPages.addListSelectionListener(this);

    setPage(homePage);

    JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(pageItem),
            new JScrollPane(selectedPages));

    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);

    /** Menu item and keyboard shortcuts for the "add page" command.  */
    fileMenu.add(createMenuItem(new AbstractAction("Add Page") {
        public void actionPerformed(ActionEvent e) {
            DefaultListModel pages = (DefaultListModel) selectedPages.getModel();
            pages.addElement(pageItem);
            selectedPages.setSelectedIndex(pages.getSize() - 1);
        }
    }, KeyEvent.VK_A, KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.ALT_MASK)));

    /** Menu item and keyboard shortcuts for the "print selected" command.*/
    fileMenu.add(createMenuItem(new AbstractAction("Print Selected") {
        public void actionPerformed(ActionEvent e) {
            printSelectedPages();
        }
    }, KeyEvent.VK_P, KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.ALT_MASK)));

    /** Menu item and keyboard shortcuts for the "clear selected" command.*/
    fileMenu.add(createMenuItem(new AbstractAction("Clear Selected") {
        public void actionPerformed(ActionEvent e) {
            DefaultListModel pages = (DefaultListModel) selectedPages.getModel();
            pages.removeAllElements();
        }
    }, KeyEvent.VK_C, KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.ALT_MASK)));

    fileMenu.addSeparator();

    /** Menu item and keyboard shortcuts for the "home page" command.  */
    fileMenu.add(createMenuItem(new AbstractAction("Home Page") {
        public void actionPerformed(ActionEvent e) {
            setPage(homePage);
        }
    }, KeyEvent.VK_H, KeyStroke.getKeyStroke(KeyEvent.VK_H, ActionEvent.ALT_MASK)));

    /** Menu item and keyboard shortcuts for the "quit" command.  */
    fileMenu.add(createMenuItem(new AbstractAction("Quit") {
        public void actionPerformed(ActionEvent e) {
            for (Window w : Window.getWindows()) {
                w.dispose();
            }
        }
    }, KeyEvent.VK_A, KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK)));

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(fileMenu);

    JPanel contentPane = new JPanel();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
    contentPane.add(pane);
    contentPane.add(messageArea);

    JFrame frame = new JFrame("Text Batch Printing Demo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setJMenuBar(menuBar);
    frame.setContentPane(contentPane);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    if (printService == null) {
        // Actual printing is not possible, issue a warning message.
        JOptionPane.showMessageDialog(frame, "No default print service", "Print Service Alert",
                JOptionPane.WARNING_MESSAGE);
    }
}

From source file:com.floreantpos.customer.DefaultCustomerListView.java

private void closeDialog(boolean canceled) {
    Window windowAncestor = SwingUtilities.getWindowAncestor(DefaultCustomerListView.this);
    if (windowAncestor instanceof POSDialog) {
        ((POSDialog) windowAncestor).setCanceled(false);
        windowAncestor.dispose();
    }/*from w  w w .  j  a va2 s .c  om*/
}