Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); if (window != null) { WindowEvent windowClosing = new WindowEvent(window, WindowEvent.WINDOW_CLOSING); window.dispatchEvent(windowClosing); }
public class CancelAction extends AbstractAction { public CancelAction() { super("Cancel"); putValue( Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_C) ); } @Override public void actionPerformed(ActionEvent e) { Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); if (window != null) { WindowEvent windowClosing = new WindowEvent(window, WindowEvent.WINDOW_CLOSING); window.dispatchEvent(windowClosing); } } }
public void actionPerformed(ActionEvent e) { Window window = SubstanceTitlePane.this.getWindow(); if (window != null) { window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING)); } } }
/** * Close the window. */ private void doParentDefaultCloseAction() { ((Window) rootParent).dispatchEvent(new WindowEvent((Window) rootParent, WindowEvent.WINDOW_CLOSING)); }
/** * Dispatch a closing event to the window. */ public static void dispatchClosingEvent(Window window) { window.dispatchEvent(createClosingEvent(window)); }
public void mousePressed(MouseEvent e) { // collapse the expanded panel and redispatch the event to the // underlying frame // for processing by the real component clicked by the user expandPanel.collapse(); Window w = SwingUtilities .getWindowAncestor(DockingDesktop.this); if (w != null) { w.dispatchEvent(e); } } });
/** Closes the Window. */ private void close() { if (window != null) { window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING)); } }
@Override public void actionPerformed(ActionEvent e) { Window window = SubstanceTitlePane.this.getWindow(); if (window != null) { window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING)); } } }
@Override public void actionPerformed(ActionEvent e) { if (window == null) return; window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING)); }
public void close() { if (window != null) { window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING)); } }
/** * Send a {@link WindowEvent#WINDOW_CLOSING} event to the supplied window. * This mimics closing by clicking the window close button. */ public static void closeWindowByEvent(Window window) { window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING)); }
JButton closeButton = new JButton("Close"); closeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Window window = SwingUtilities.windowForComponent((JButton)e.getSource()); window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING)); } }); ... JFrame frame = new JFrame("Frame"); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { // Call methodA() here. // If all went ok then dispose the window, otherwise log the // errors/exceptions and notify the user that something went wrong. e.getWindow().dispose(); } });
@Override public void dispose() { Window frame = getOwner(); super.dispose(); if (!pluginMode) { frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING)); } }
/** * Closes the Window. */ private void close() { Window window = getWindow(); if (window != null) { window.dispatchEvent( new WindowEvent(window, WindowEvent.WINDOW_CLOSING)); } }
public void widgetActivated(WidgetEvent evt) { Window window = SwingUtilities.windowForComponent(ObjectTreeInternalFrame.this.getObjectTreePanel()); Component focusOwner = (window != null) ? window.getFocusOwner() : null; if (focusOwner != null) { FocusEvent lost = new FocusEvent(focusOwner, FocusEvent.FOCUS_LOST); FocusEvent gained = new FocusEvent(focusOwner, FocusEvent.FOCUS_GAINED); window.dispatchEvent(lost); window.dispatchEvent(gained); window.dispatchEvent(lost); focusOwner.requestFocus(); } } });
public void widgetActivated(WidgetEvent evt) { Window window = SwingUtilities.windowForComponent(ObjectTreeInternalFrame.this.getObjectTreePanel()); Component focusOwner = (window != null) ? window.getFocusOwner() : null; if (focusOwner != null) { FocusEvent lost = new FocusEvent(focusOwner, FocusEvent.FOCUS_LOST); FocusEvent gained = new FocusEvent(focusOwner, FocusEvent.FOCUS_GAINED); window.dispatchEvent(lost); window.dispatchEvent(gained); window.dispatchEvent(lost); focusOwner.requestFocus(); } } });
/** * closes the window, i.e., if the parent is not null and implements the * WindowListener interface it calls the windowClosing method */ public void close() { if (getParentInternalFrame() != null) { getParentInternalFrame().doDefaultCloseAction(); } else if (getParentFrame() != null) { ((Window) getParentFrame()).dispatchEvent(new WindowEvent( getParentFrame(), WindowEvent.WINDOW_CLOSING)); } }
/** * closes the window, i.e., if the parent is not null and implements the * WindowListener interface it calls the windowClosing method */ public void close() { if (getParentInternalFrame() != null) { getParentInternalFrame().doDefaultCloseAction(); } else if (getParentFrame() != null) { ((Window) getParentFrame()).dispatchEvent(new WindowEvent( getParentFrame(), WindowEvent.WINDOW_CLOSING)); } }
/** * closes the window, i.e., if the parent is not null and implements the * WindowListener interface it calls the windowClosing method */ public void close() { if (getParentInternalFrame() != null) { getParentInternalFrame().doDefaultCloseAction(); } else if (getParentFrame() != null) { ((Window) getParentFrame()).dispatchEvent(new WindowEvent( getParentFrame(), WindowEvent.WINDOW_CLOSING)); } }
/** * closes the window, i.e., if the parent is not null and implements the * WindowListener interface it calls the windowClosing method */ public void close() { if (getParentInternalFrame() != null) { getParentInternalFrame().doDefaultCloseAction(); } else if (getParentFrame() != null) { ((Window) getParentFrame()).dispatchEvent(new WindowEvent( getParentFrame(), WindowEvent.WINDOW_CLOSING)); } }