private JFrame f = new JFrame("FullScreenTest"); private Action exit = new AbstractAction(EXIT) { f.dispatchEvent(new WindowEvent( f, WindowEvent.WINDOW_CLOSING)); private JButton b = new JButton(exit); this.add(b); f.getRootPane().setDefaultButton(b); this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, 0), EXIT); this.getActionMap().put(EXIT, exit); this.addMouseMotionListener(new MouseAdapter() { GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice dev = env.getDefaultScreenDevice(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setBackground(Color.darkGray); f.setResizable(false); f.setUndecorated(true); f.add(this); f.pack(); dev.setFullScreenWindow(f);
/** * @see java.awt.event.WindowAdapter#windowClosing(java.awt.event.WindowEvent) */ @Override public void windowClosing(WindowEvent e) { // TODO SWINGWORKER fix closing of main window with correct storing of preferences closeAllButSelectedDocument(((GCViewerGui)e.getWindow())); GCPreferences preferences = copyPreferencesFromGui(((GCViewerGui)e.getWindow())); preferences.store(); e.getWindow().dispose(); }
protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { switch(defaultCloseOperation) { ... case EXIT_ON_CLOSE: // This needs to match the checkExit call in // setDefaultCloseOperation System.exit(0); break; } } }
final JFrame frame = new JFrame("Login"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); JButton button = new JButton("Accept"); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if("user".equals(textField.getText())){ frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING)); login.add(new JLabel("User")); login.add(textField); login.add(button); frame.getContentPane().add(login); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true);
file.add(fileNew); final JFrame frame1 = new JFrame("First"); frame1.getContentPane().add(new JButton("First")); frame1.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); final JFrame frame2 = new JFrame("Second"); frame2.getContentPane().add(new JButton("Second")); frame2.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); @Override public void windowActivated(WindowEvent e) { ((JFrame) e.getWindow()).setJMenuBar(menuBar); frame1.addWindowListener(listener); frame2.addWindowListener(listener); frame1.pack(); frame1.setLocation(offsetX, offsetY); frame1.setVisible(true); frame2.pack(); frame2.setLocation(frame1.getWidth() + offsetX + 10, offsetY); frame2.setVisible(true);
this.add(new JLabel("Dialog close test.", JLabel.CENTER)); this.add(new JButton(new AbstractAction("Close") { DialogClose.this.dispatchEvent(new WindowEvent( DialogClose.this, WindowEvent.WINDOW_CLOSING)); this.pack(); this.setLocationRelativeTo(null); this.setVisible(true);
e.getWindow().setVisible(false); JButton button = new JButton("Show Popup"); button.addActionListener(new ActionListener() dialog.add( new JButton("Dummy Button") ); dialog.pack(); dialog.setLocationRelativeTo( frame ); dialog.setVisible( true ); dialog.addWindowListener( wl ); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(button, BorderLayout.NORTH); frame.setSize(400, 400); frame.setLocationRelativeTo( null );
JFrame frame = new JFrame("Stack Overflow"); frame.setBounds(100, 100, 800, 600); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); panel.add(new JLabel("Testing multiple windows...")); frame.getContentPane().add(panel); public void windowOpened(WindowEvent windowEvent) { System.out.println("Window opened: " + windowEvent.getWindow().getName()); public void windowClosed(WindowEvent windowEvent) { System.out.println("Window closed: " + windowEvent.getWindow().getName()); String title = "Window " + windowIndex; JFrame extraFrame = new JFrame(title); extraFrame.setName(title); extraFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); extraFrame.addWindowListener(windowAdapter); extraFrame.setVisible(true);
setLayout(new BorderLayout()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Exit"); add(button); new WindowEvent( ExitJFrame.this, WindowEvent.WINDOW_CLOSING)); setSize(200, 200); setLocationRelativeTo(null); dialog.setUndecorated(true); JProgressBar progress = new JProgressBar(); dialog.add(progress); dialog.add(new JLabel("Waiting for non-daemon threads to exit gracefully..."), BorderLayout.NORTH); progress.setIndeterminate(true); dialog.dispose();
System.out.println(e.getWindow().getName() + ":" + e); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setTitle(String.valueOf(i)); f.add(new MyPanel()); f.addWindowListener(listener); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true);
JFrame frame = new JFrame("Title"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationByPlatform(true); timer.setCoalesce(false); optPane.setMessage(message()); optPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); optPane.setOptionType(JOptionPane.DEFAULT_OPTION); optPane.addPropertyChangeListener(this); dialog.add(optPane); dialog.pack(); frame.add(new JLabel(frame.getTitle(), JLabel.CENTER)); frame.setVisible(true); dialog.setLocationRelativeTo(frame); dialog.setVisible(true); dialog.dispatchEvent(new WindowEvent( dialog, WindowEvent.WINDOW_CLOSING));
JFrame myFrame = new JFrame("Window Close Dialog Application"); myFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); myFrame.addWindowListener(this);//catch the window being closed ... closeDialog = new JDialog("Quit"); closeDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); closeDialog.addWindowListener(this);//catch the dialog being closed JLabel closeLabel = new JLabel("Would you like to exit?"); yesButton = new JButton("Yes"); yesButton.addActionListener(this);//catch an answer of yes noButton = new JButton("No"); noButton.addActionListener(this);//catch an answer of no @Override public void windowClosing(WindowEvent w) { if (w.getWindow().equals(myFrame)) { closeDialog.setVisible(true); } else if (w.getWindow().equals(closeDialog)) { closeDialog.setVisible(false);//no exit on dialog close
JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel); frame.addWindowStateListener(new WindowAdapter() { @Override public void windowStateChanged(WindowEvent we) { if (we.getNewState() == Frame.ICONIFIED) { System.out.println("Here"); frame.pack(); frame.setVisible(true);
public void actionPerformed(ActionEvent evt) { final JButton finalButton = button; button.setEnabled(false); JFrame frame = new JFrame() { protected void processWindowEvent(WindowEvent e) { if (e.getID() == WindowEvent.WINDOW_CLOSING) { finalButton.setEnabled(true); } super.processWindowEvent(e); } }; frame.setVisible(true); }
@Override public void windowClosing(WindowEvent e){ JFrame f = (JFrame) e.getSource(); f.setVisible(false); f.dispose(); }
setTitle("this panel will self-destruct"); setDefaultCloseOperation(DISPOSE_ON_CLOSE); final JProgressBar progressBar = new JProgressBar(SwingConstants.HORIZONTAL, 0, 100); add(progressBar); pack(); every50millis = new Timer(50, new ActionListener() { private int count=0; System.err.println("shutting down"); every50millis.stop(); WindowEvent closingEvent = new WindowEvent(ClosingPanel.this, WindowEvent.WINDOW_CLOSING); Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(closingEvent); public void run() { ClosingPanel panel = new ClosingPanel(); panel.setVisible(true);
/** * closing Event. Shows a warning if this window has unsaved data and * terminates jvm, if last window. * * @param e * Description of the Parameter */ public void windowClosing(WindowEvent e) { int clear = ((JChemPaintPanel) ((JFrame) e.getSource()) .getContentPane().getComponents()[0]).showWarning(); if (JOptionPane.CANCEL_OPTION != clear) { for (int i = 0; i < instances.size(); i++) { if (instances.get(i).getTopLevelContainer() == (JFrame) e .getSource()) { instances.remove(i); break; } } ((JFrame) e.getSource()).setVisible(false); ((JFrame) e.getSource()).dispose(); if (instances.size() == 0) {// TODO && // !((JChemPaintPanel)rootFrame.getContentPane().getComponent(0)).isEmbedded()) // { System.exit(0); } } } }
Frame frame = new Frame("My AWT Application"); Canvas parentCanvas = new Canvas(); frame.add(parentCanvas, BorderLayout.CENTER); frame.pack(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { e.getWindow().dispose(); while (frame.isDisplayable()) { if (!display.readAndDispatch()) { display.sleep();
@ScriptFunction(params = {"obj"}, jsDoc = CLOSE_JSDOC) public void close(Object aSelected) { if (surface != null) { try { if (surface instanceof Window) { windowHandler.windowClosing(new WindowEvent(((Window) surface), WindowEvent.WINDOW_CLOSING)); ((Window) surface).dispose(); } else if (surface instanceof JInternalFrame) { windowHandler.internalFrameClosing(new InternalFrameEvent(((JInternalFrame) surface), WindowEvent.WINDOW_CLOSING)); ((JInternalFrame) surface).dispose(); } else { windowHandler.windowClosing(new WindowEvent(new JFrame(), WindowEvent.WINDOW_CLOSING)); windowHandler.windowClosed(new WindowEvent(new JFrame(), WindowEvent.WINDOW_CLOSED)); view.invalidate(); surface.remove(view); surface.validate(); surface.repaint(); } surface = null; closeCallbackParameter = aSelected; } catch (ClosedManageException ex) { // no op } } }
final JFrame frame = (JFrame) e.getSource(); if ((e.getNewState() & Frame.ICONIFIED) != 0) { try { frame.dispose(); } catch (AWTException ex) { LOGGER.error("Couldn't create a tray icon, the minimizing is not possible", ex); frame.setVisible(true);