java.awt.event.WindowListener Java Examples
The following examples show how to use
java.awt.event.WindowListener.
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: JOptionPane.java From Java8CN with Apache License 2.0 | 6 votes |
private JDialog createDialog(Component parentComponent, String title, int style) throws HeadlessException { final JDialog dialog; Window window = JOptionPane.getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame)window, title, true); } else { dialog = new JDialog((Dialog)window, title, true); } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); return dialog; }
Example #2
Source File: JOptionPane.java From hottub with GNU General Public License v2.0 | 6 votes |
private JDialog createDialog(Component parentComponent, String title, int style) throws HeadlessException { final JDialog dialog; Window window = JOptionPane.getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame)window, title, true); } else { dialog = new JDialog((Dialog)window, title, true); } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); return dialog; }
Example #3
Source File: JOptionPane.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
private JDialog createDialog(Component parentComponent, String title, int style) throws HeadlessException { final JDialog dialog; Window window = JOptionPane.getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame)window, title, true); } else { dialog = new JDialog((Dialog)window, title, true); } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); return dialog; }
Example #4
Source File: JOptionPane.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private JDialog createDialog(Component parentComponent, String title, int style) throws HeadlessException { final JDialog dialog; Window window = JOptionPane.getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame)window, title, true); } else { dialog = new JDialog((Dialog)window, title, true); } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); return dialog; }
Example #5
Source File: JOptionPane.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
private JDialog createDialog(Component parentComponent, String title, int style) throws HeadlessException { final JDialog dialog; Window window = JOptionPane.getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame)window, title, true); } else { dialog = new JDialog((Dialog)window, title, true); } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); return dialog; }
Example #6
Source File: SwingSet2.java From beautyeye with Apache License 2.0 | 6 votes |
/** * Create a frame for SwingSet2 to reside in if brought up * as an application. * * @param gc the gc * @return the j frame */ public static JFrame createFrame(GraphicsConfiguration gc) { JFrame frame = new JFrame(gc); if (numSSs == 0) { frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } else { WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { numSSs--; swingSets.remove(this); } }; frame.addWindowListener(l); } //由Jack Jiang于2012-09-22加上,防止因JToolBar的大小而影响JFrame的prefereSize使得没法再缩小 frame.setMinimumSize(new Dimension(100,100)); return frame; }
Example #7
Source File: JOptionPane.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private JDialog createDialog(Component parentComponent, String title, int style) throws HeadlessException { final JDialog dialog; Window window = JOptionPane.getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame)window, title, true); } else { dialog = new JDialog((Dialog)window, title, true); } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); return dialog; }
Example #8
Source File: JOptionPane.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
private JDialog createDialog(Component parentComponent, String title, int style) throws HeadlessException { final JDialog dialog; Window window = JOptionPane.getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame)window, title, true); } else { dialog = new JDialog((Dialog)window, title, true); } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); return dialog; }
Example #9
Source File: JOptionPane.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private JDialog createDialog(Component parentComponent, String title, int style) throws HeadlessException { final JDialog dialog; Window window = JOptionPane.getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame)window, title, true); } else { dialog = new JDialog((Dialog)window, title, true); } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); return dialog; }
Example #10
Source File: RevisionPicker.java From netbeans with Apache License 2.0 | 6 votes |
public boolean open () { dd = new DialogDescriptor(panel, NbBundle.getMessage(RevisionPicker.class, "LBL_RevisionPickerDialog.title"), //NOI18N true, new Object[] { okButton, DialogDescriptor.CANCEL_OPTION }, okButton, DialogDescriptor.DEFAULT_ALIGN, new HelpCtx("org.netbeans.modules.git.ui.repository.RevisionPickerDialog"), null); //NOI18N Dialog dialog = DialogDisplayer.getDefault().createDialog(dd); updateDialogState(); browserPanel.addPropertyChangeListener(this); Preferences prefs = GitModuleConfig.getDefault().getPreferences(); WindowListener windowListener = new DialogBoundsPreserver(prefs, this.getClass().getName()); dialog.addWindowListener(windowListener); windowListener.windowOpened(new WindowEvent(dialog, WindowEvent.WINDOW_OPENED)); dialog.pack(); updateSliders(prefs); dialog.setVisible(true); persistSliders(prefs); browserPanel.removePropertyChangeListener(this); return dd.getValue() == okButton; }
Example #11
Source File: JOptionPane.java From Bytecoder with Apache License 2.0 | 6 votes |
private JDialog createDialog(Component parentComponent, String title, int style) throws HeadlessException { final JDialog dialog; Window window = JOptionPane.getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame)window, title, true); } else { dialog = new JDialog((Dialog)window, title, true); } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); return dialog; }
Example #12
Source File: JOptionPane.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private JDialog createDialog(Component parentComponent, String title, int style) throws HeadlessException { final JDialog dialog; Window window = JOptionPane.getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame)window, title, true); } else { dialog = new JDialog((Dialog)window, title, true); } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); return dialog; }
Example #13
Source File: JOptionPane.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private JDialog createDialog(Component parentComponent, String title, int style) throws HeadlessException { final JDialog dialog; Window window = JOptionPane.getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame)window, title, true); } else { dialog = new JDialog((Dialog)window, title, true); } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); return dialog; }
Example #14
Source File: JOptionPane.java From JDKSourceCode1.8 with MIT License | 6 votes |
private JDialog createDialog(Component parentComponent, String title, int style) throws HeadlessException { final JDialog dialog; Window window = JOptionPane.getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame)window, title, true); } else { dialog = new JDialog((Dialog)window, title, true); } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); return dialog; }
Example #15
Source File: GuiUtilities.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public static void addClosingListener( JFrame frame, IOnCloseListener onCloseListener ) { WindowListener exitListener = new WindowAdapter(){ @Override public void windowClosing( WindowEvent e ) { if (!onCloseListener.canCloseWithoutPrompt()) { int confirm = JOptionPane.showOptionDialog(frame, "Are you sure you want to exit?", "Exit Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (confirm == JOptionPane.YES_OPTION) { onCloseListener.onClose(); System.exit(0); } } else { onCloseListener.onClose(); System.exit(0); } } }; frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); frame.addWindowListener(exitListener); }
Example #16
Source File: JOptionPane.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
private JDialog createDialog(Component parentComponent, String title, int style) throws HeadlessException { final JDialog dialog; Window window = JOptionPane.getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame)window, title, true); } else { dialog = new JDialog((Dialog)window, title, true); } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); return dialog; }
Example #17
Source File: Client.java From cloudstack with Apache License 2.0 | 6 votes |
protected static Frame createVncClientMainWindow(BufferedImageCanvas canvas, String title, WindowListener windowListener) { // Create AWT windows Frame frame = new Frame(title + " - RDP"); // Use scrolling pane to support screens, which are larger than ours scroller = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED); scroller.add(canvas); scroller.setSize(canvas.getWidth(), canvas.getHeight()); frame.add(scroller); frame.pack(); frame.setVisible(true); frame.addWindowListener(windowListener); return frame; }
Example #18
Source File: JOptionPane.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private JDialog createDialog(Component parentComponent, String title, int style) throws HeadlessException { final JDialog dialog; Window window = JOptionPane.getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame)window, title, true); } else { dialog = new JDialog((Dialog)window, title, true); } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); return dialog; }
Example #19
Source File: JOptionPane.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private JDialog createDialog(Component parentComponent, String title, int style) throws HeadlessException { final JDialog dialog; Window window = JOptionPane.getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame)window, title, true); } else { dialog = new JDialog((Dialog)window, title, true); } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); return dialog; }
Example #20
Source File: JOptionPane.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private JDialog createDialog(Component parentComponent, String title, int style) throws HeadlessException { final JDialog dialog; Window window = JOptionPane.getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame)window, title, true); } else { dialog = new JDialog((Dialog)window, title, true); } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); return dialog; }
Example #21
Source File: JOptionPane.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
private JDialog createDialog(Component parentComponent, String title, int style) throws HeadlessException { final JDialog dialog; Window window = JOptionPane.getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame)window, title, true); } else { dialog = new JDialog((Dialog)window, title, true); } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); return dialog; }
Example #22
Source File: ChartPanel.java From cropplanning with GNU General Public License v3.0 | 6 votes |
public static void main(String[] argv) { JFrame f = new JFrame(); f.setSize(400, 300); int size = 30; List<Double> values = new ArrayList<Double>( size ); List<String> names = new ArrayList<String>( size ); for ( int i = 0; i < size; i++ ) { values.add( i * 1d ); names.add( "Item " + i ); } f.getContentPane().add(new ChartPanel( values, names, "A title")); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; f.addWindowListener(wndCloser); f.setVisible(true); }
Example #23
Source File: Launcher.java From osp with GNU General Public License v3.0 | 6 votes |
private void exitCurrentApps() { final Frame[] prevFrames = Frame.getFrames(); for(int i = 0, n = prevFrames.length; i<n; i++) { if(existingFrames.contains(prevFrames[i])) { continue; // don't mess with pre-existing frames such as the applet plugin } if(!(prevFrames[i] instanceof LauncherFrame)) { WindowListener[] listeners = prevFrames[i].getWindowListeners(); for(int j = 0; j<listeners.length; j++) { listeners[j].windowClosing(null); } if(prevFrames[i].isVisible()) { prevFrames[i].dispose(); } } } }
Example #24
Source File: EventWait.java From swift-k with Apache License 2.0 | 5 votes |
private void waitForEvent(LWThread thr, Stack stack) { k.rt.Channel<Object> vargs = c_vargs.get(stack); FutureCounter counter = new FutureCounter(vargs.size()); for (Object arg : vargs) { if (!(arg instanceof List)) { throw new ExecutionException("Each argument must be a list"); } List<?> list = (List<?>) arg; if (list.size() != 3) { throw new ExecutionException("Each argument must be a list containing 3 items"); } try { String ret = (String) list.get(0); String type = (String) list.get(1); Object source = list.get(2); if ("java.awt.events.ActionEvent".equals(type)) { addListener(source, "addActionListener", ActionListener.class, counter); } else if ("java.awt.events.WindowEvent".equals(type)) { addListener(source, "addWindowListener", WindowListener.class, counter); } else { throw new ExecutionException("Unknown event type: " + type); } } catch (Exception e) { throw new ExecutionException("Exception caught while adding listener", e); } } throw new ConditionalYield(2, 3, counter); }
Example #25
Source File: WindowOperator.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Maps {@code Window.addWindowListener(WindowListener)} through queue */ public void addWindowListener(final WindowListener windowListener) { runMapping(new MapVoidAction("addWindowListener") { @Override public void map() { ((Window) getSource()).addWindowListener(windowListener); } }); }
Example #26
Source File: MouseGrabberUtil.java From darklaf with MIT License | 5 votes |
/** * This Method is responsible for removing the old MouseGrabber from the AppContext, to be able to add our own * implementation for it that is a bit more generous with closing the popup. */ public static void uninstallOldMouseGrabber(final ChangeListener oldMouseGrabber) { if (oldMouseGrabber == null) return; MenuSelectionManager menuSelectionManager = MenuSelectionManager.defaultManager(); menuSelectionManager.removeChangeListener(oldMouseGrabber); if (oldMouseGrabber instanceof AWTEventListener) { Toolkit tk = Toolkit.getDefaultToolkit(); java.security.AccessController.doPrivileged((PrivilegedAction<Object>) () -> { tk.removeAWTEventListener((AWTEventListener) oldMouseGrabber); return null; }); } MenuElement[] path = menuSelectionManager.getSelectedPath(); if (path.length != 0 && path[0] != null) { Component invoker = path[0].getComponent(); if (invoker instanceof JPopupMenu) { invoker = ((JPopupMenu) invoker).getInvoker(); } Window grabbedWindow = DarkUIUtil.getWindow(invoker); if (oldMouseGrabber instanceof WindowListener) { grabbedWindow.removeWindowListener((WindowListener) oldMouseGrabber); } if (oldMouseGrabber instanceof ComponentListener) { grabbedWindow.removeComponentListener((ComponentListener) oldMouseGrabber); } } }
Example #27
Source File: SwingUtils.java From RipplePower with Apache License 2.0 | 5 votes |
public static void addWindowListener(final Component source, final WindowListener listener) { if (source instanceof Window) { ((Window) source).addWindowListener(listener); } else { source.addHierarchyListener(new HierarchyListener() { @Override public void hierarchyChanged(HierarchyEvent e) { if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) == HierarchyEvent.SHOWING_CHANGED) { SwingUtilities.getWindowAncestor(source).addWindowListener(listener); } } }); } }
Example #28
Source File: LoadingDialog.java From jpexs-decompiler with GNU General Public License v3.0 | 5 votes |
@Override public void dispose() { removeAll(); for (WindowListener windowListener : getWindowListeners()) { removeWindowListener(windowListener); } Helper.emptyObject(this); super.dispose(); }
Example #29
Source File: SwingHelper.java From universal-tween-engine with Apache License 2.0 | 5 votes |
/** * Adds a listener to the window parent of the given component. Can be * before the component is really added to its hierachy. * @param source The source component * @param listener The listener to add to the window */ public static void addWindowListener(final Component source, final WindowListener listener) { if (source instanceof Window) { ((Window)source).addWindowListener(listener); } else { source.addHierarchyListener(new HierarchyListener() { @Override public void hierarchyChanged(HierarchyEvent e) { if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) == HierarchyEvent.SHOWING_CHANGED) { SwingUtilities.getWindowAncestor(source).addWindowListener(listener); } } }); } }
Example #30
Source File: LaunchNode.java From osp with GNU General Public License v3.0 | 5 votes |
/** * Terminates all apps launched by this node. */ public void terminateAll() { for(Iterator<Process> it = processes.iterator(); it.hasNext(); ) { Process proc = it.next(); proc.destroy(); } for(Iterator<Frame> it = frames.iterator(); it.hasNext(); ) { Frame frame = it.next(); WindowListener[] listeners = frame.getWindowListeners(); for(int j = 0; j<listeners.length; j++) { if(listeners[j] instanceof Launcher.FrameCloser) { frame.removeWindowListener(listeners[j]); } } frame.dispose(); } for(Iterator<Thread> it = threads.values().iterator(); it.hasNext(); ) { Thread thread = it.next(); if(thread!=null) { thread.interrupt(); } } Collection<Action> allActions = new HashSet<Action>(actions); for(Iterator<Action> it = allActions.iterator(); it.hasNext(); ) { Action action = it.next(); if(action!=null) { action.actionPerformed(null); } } processes.clear(); frames.clear(); threads.clear(); actions.clear(); launchCount = 0; }