Example usage for java.awt.event WindowAdapter WindowAdapter

List of usage examples for java.awt.event WindowAdapter WindowAdapter

Introduction

In this page you can find the example usage for java.awt.event WindowAdapter WindowAdapter.

Prototype

WindowAdapter

Source Link

Usage

From source file:com.chenjw.imagegrab.ui.MainFrame.java

public MainFrame() {
    {/*from  w w  w.  j  av  a  2 s .  c  o  m*/
        this.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }

        });
    }

    GroupLayout configPanelLayout = new GroupLayout((JComponent) configPanel);
    configPanel.setLayout(configPanelLayout);
    configPanel.setPreferredSize(new java.awt.Dimension(1035, 726));
    {
        downloadButton = new JButton();
        downloadButton.setText("");
        downloadButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                executeService.execute(new Runnable() {
                    @Override
                    public void run() {
                        imagegrabService.grab();
                    }
                });

            }

        });
        downloadButton.registerKeyboardAction(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                executeService.execute(new Runnable() {
                    @Override
                    public void run() {
                        imagegrabService.grab();
                    }
                });
            }
        }, KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_DOWN_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW);
    }
    {
        jLabel1 = new JLabel();
        jLabel1.setText("??");
    }
    {
        resultScrollPane = new JScrollPane(resultPane);
        {
            resultPane = new JTextArea();
            resultScrollPane.setViewportView(resultPane);
        }
    }
    {
        sourceComboBox = new JComboBox();
    }
    {

        maxNumComboBox = new HistoryComboBox("maxNum");
    }
    {
        jLabel6 = new JLabel();
        jLabel6.setText("??");
    }
    {
        jLabel3 = new JLabel();
        jLabel3.setText("??");
    }

    {
        searchWordComboBox = new HistoryComboBox("searchWord");
    }
    configPanelLayout.setHorizontalGroup(configPanelLayout.createSequentialGroup().addContainerGap()
            .addGroup(configPanelLayout.createParallelGroup()
                    .addGroup(configPanelLayout.createSequentialGroup()
                            .addComponent(resultScrollPane, GroupLayout.PREFERRED_SIZE, 979,
                                    GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(GroupLayout.Alignment.LEADING, configPanelLayout.createSequentialGroup()
                            .addPreferredGap(resultScrollPane, jLabel1, LayoutStyle.ComponentPlacement.INDENT)
                            .addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(searchWordComboBox, 0, 213, Short.MAX_VALUE)
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabel3, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE)
                            .addComponent(sourceComboBox, GroupLayout.PREFERRED_SIZE, 112,
                                    GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jLabel6, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(maxNumComboBox, GroupLayout.PREFERRED_SIZE, 72,
                                    GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(downloadButton, GroupLayout.PREFERRED_SIZE, 162,
                                    GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 164, GroupLayout.PREFERRED_SIZE)))
            .addContainerGap());
    configPanelLayout.setVerticalGroup(configPanelLayout.createSequentialGroup().addContainerGap()
            .addGroup(configPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 27,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 27,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(searchWordComboBox, GroupLayout.Alignment.BASELINE,
                            GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 27,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(sourceComboBox, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                            27, GroupLayout.PREFERRED_SIZE)
                    .addComponent(downloadButton, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                            27, GroupLayout.PREFERRED_SIZE)
                    .addComponent(maxNumComboBox, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                            27, GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 698, GroupLayout.PREFERRED_SIZE)
            .addComponent(resultScrollPane, GroupLayout.PREFERRED_SIZE, 686, GroupLayout.PREFERRED_SIZE));
    //
    pack();
    this.setSize(1010, 768);
    setVisible(true);
    this.setTitle("?");
    getContentPane().add(configPanel, BorderLayout.CENTER);
    initSpring();
}

From source file:sample.fa.ScriptRunnerApplication.java

void createGUI() {
    Box buttonBox = Box.createHorizontalBox();

    JButton loadButton = new JButton("Load");
    loadButton.addActionListener(this::loadScript);
    buttonBox.add(loadButton);/*from  w  ww. j a v  a 2  s.c  o  m*/

    JButton saveButton = new JButton("Save");
    saveButton.addActionListener(this::saveScript);
    buttonBox.add(saveButton);

    JButton executeButton = new JButton("Execute");
    executeButton.addActionListener(this::executeScript);
    buttonBox.add(executeButton);

    languagesModel = new DefaultComboBoxModel();

    ScriptEngineManager sem = new ScriptEngineManager();
    for (ScriptEngineFactory sef : sem.getEngineFactories()) {
        languagesModel.addElement(sef.getScriptEngine());
    }

    JComboBox<ScriptEngine> languagesCombo = new JComboBox<>(languagesModel);
    JLabel languageLabel = new JLabel();
    languagesCombo.setRenderer((JList<? extends ScriptEngine> list, ScriptEngine se, int index,
            boolean isSelected, boolean cellHasFocus) -> {
        ScriptEngineFactory sef = se.getFactory();
        languageLabel.setText(sef.getEngineName() + " - " + sef.getLanguageName() + " (*."
                + String.join(", *.", sef.getExtensions()) + ")");
        return languageLabel;
    });
    buttonBox.add(Box.createHorizontalGlue());
    buttonBox.add(languagesCombo);

    scriptContents = new JTextArea();
    scriptContents.setRows(8);
    scriptContents.setColumns(40);

    scriptResults = new JTextArea();
    scriptResults.setEditable(false);
    scriptResults.setRows(8);
    scriptResults.setColumns(40);

    JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scriptContents, scriptResults);

    JFrame frame = new JFrame("Script Runner");
    frame.add(buttonBox, BorderLayout.NORTH);
    frame.add(jsp, BorderLayout.CENTER);

    frame.pack();
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    frame.setVisible(true);
}

From source file:com.sshtools.powervnc.PowerVNCFullScreenWindowContainer.java

public void init(final SshToolsApplication application, SshToolsApplicationPanel panel)
        throws SshToolsApplicationException {
    getContentPane().invalidate();//  w ww . ja  v a  2s . c o m
    //setUndecorated(true);
    this.panel = panel;
    this.application = application;
    setJMenuBar(((PowerVNCPanel) panel).getJMenuBar());
    // We dont want the status bar, menu bar or tool bar showing in full screen mode by default
    ((PowerVNCPanel) panel).setToolsVisible(false);
    panel.registerActionMenu(new SshToolsApplicationPanel.ActionMenu("File", "File", 'f', 0));
    panel.registerAction(exitAction = new ExitAction(application, this));
    panel.registerAction(newWindowAction = new NewWindowAction(application));
    panel.registerAction(aboutAction = new AboutAction(this, application));
    panel.registerAction(fullScreenAction = new FullScreenActionImpl(application, this));

    getApplicationPanel().rebuildActionComponents();
    JPanel p = new JPanel(new BorderLayout());
    if (panel.getToolBar() != null) {
        JPanel t = new JPanel(new BorderLayout());
        t.add(panel.getToolBar(), BorderLayout.NORTH);
        t.add(toolSeperator = new JSeparator(JSeparator.HORIZONTAL), BorderLayout.SOUTH);
        final SshToolsApplicationPanel pnl = panel;
        panel.getToolBar().addComponentListener(new ComponentAdapter() {
            public void componentHidden(ComponentEvent evt) {
                log.debug("Tool separator is now " + pnl.getToolBar().isVisible());
                toolSeperator.setVisible(pnl.getToolBar().isVisible());
            }
        });
        p.add(t, BorderLayout.NORTH);
    }
    p.add(panel, BorderLayout.CENTER);
    if (panel.getStatusBar() != null) {
        p.add(panel.getStatusBar(), BorderLayout.SOUTH);
    }
    getContentPane().setLayout(new GridLayout(1, 1));
    getContentPane().add(p);
    // Watch for the frame closing
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            application.closeContainer(PowerVNCFullScreenWindowContainer.this);
        }
    });
    getContentPane().validate();
}

From source file:net.sf.keystore_explorer.gui.dialogs.DCheckUpdate.java

private void initComponents() {
    jlCheckUpdate = new JLabel(res.getString("DCheckUpdate.jlCheckUpdate.text"));
    ImageIcon icon = new ImageIcon(getClass().getResource(res.getString("DCheckUpdate.jlCheckUpdate.image")));
    jlCheckUpdate.setIcon(icon);//from ww  w .ja v a  2  s.  c  o  m
    jlCheckUpdate.setHorizontalTextPosition(SwingConstants.LEADING);
    jlCheckUpdate.setIconTextGap(15);

    jpCheckUpdate = new JPanel(new FlowLayout(FlowLayout.CENTER));
    jpCheckUpdate.add(jlCheckUpdate);
    jpCheckUpdate.setBorder(new EmptyBorder(5, 5, 5, 5));

    jpbCheckUpdate = new JProgressBar();
    jpbCheckUpdate.setIndeterminate(true);
    jpbCheckUpdate.setString("DCheckUpdate.jlCheckUpdate.text");

    jpProgress = new JPanel(new FlowLayout(FlowLayout.CENTER));
    jpProgress.add(jpbCheckUpdate);
    jpProgress.setBorder(new EmptyBorder(5, 5, 5, 5));

    jbCancel = new JButton(res.getString("DCheckUpdate.jbCancel.text"));
    jbCancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            cancelPressed();
        }
    });
    jbCancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            CANCEL_KEY);
    jbCancel.getActionMap().put(CANCEL_KEY, new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            cancelPressed();
        }
    });

    jpCancel = PlatformUtil.createDialogButtonPanel(jbCancel, false);

    getContentPane().add(jpCheckUpdate, BorderLayout.NORTH);
    getContentPane().add(jpProgress, BorderLayout.CENTER);
    getContentPane().add(jpCancel, BorderLayout.SOUTH);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent evt) {
            if ((checker != null) && (checker.isAlive())) {
                checker.interrupt();
            }
            closeDialog();
        }
    });

    setTitle(res.getString("DCheckUpdate.Title"));
    setResizable(false);

    pack();
}

From source file:view.caja.Despacho.java

public Despacho(Usuario usuario) {
    productoController = new ProductoController();
    clienteController = new ClienteController();
    cl = clienteController.mostrarClientes();
    aCobrar = 0;//from  w  w  w .  ja  v a  2 s.  c  o m
    this.usuario = usuario;
    cambio = 0;
    initGUI();
    //cl = clienteController.get
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    pack();
}

From source file:com.diversityarrays.kdxplore.curate.fieldview.OverviewDialog.java

@SuppressWarnings("unchecked")
public OverviewDialog(Window window, String title,

        @SuppressWarnings("rawtypes") ComboBoxModel comboBoxModel, CurationData curationData,
        Transformer<TraitInstance, String> tiNameProvider, OverviewInfoProvider overviewInfoProvider,
        FieldViewSelectionModel fvsm, FieldLayoutTableModel fltm, CurationTableModel ctm) {
    super(window, title, ModalityType.MODELESS);

    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    setAlwaysOnTop(true);//from w w  w  . j av a  2  s .c  o m

    this.fieldViewSelectionModel = fvsm;

    @SuppressWarnings({ "rawtypes" })
    JComboBox activeTiCombo = new JComboBox(comboBoxModel);
    TraitInstanceCellRenderer tiCellRenderer = new TraitInstanceCellRenderer(
            curationData.getTraitColorProvider(), tiNameProvider);
    activeTiCombo.setRenderer(tiCellRenderer);

    JLabel infoLabel = new JLabel(" ");
    infoLabel.setBorder(new BevelBorder(BevelBorder.LOWERED));

    final JFrame[] helpDialog = new JFrame[1];
    Action helpAction = new AbstractAction("?") {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (helpDialog[0] != null) {
                GuiUtil.restoreFrame(helpDialog[0]);
            } else {
                JFrame f = new JFrame("Overview Help");
                helpDialog[0] = f;
                f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                f.setAlwaysOnTop(true);
                f.setLocationRelativeTo(overview);
                String html = Overview.getOverviewHelpHtml();
                JLabel label = new JLabel(html);
                label.setBorder(new EmptyBorder(0, 10, 0, 10));
                f.setContentPane(label);
                f.pack();
                f.setVisible(true);
            }
        }
    };

    //        Window window = GuiUtil.getOwnerWindow(FieldLayoutViewPanel.this);
    if (window != null) {
        if (window instanceof JFrame) {
            System.out.println("Found window: " + ((JFrame) window).getTitle());
        }
        window.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosed(WindowEvent e) {
                window.removeWindowListener(this);
                if (helpDialog[0] != null) {
                    helpDialog[0].dispose();
                }
            }
        });
    }

    KDClientUtils.initAction(ImageId.HELP_24, helpAction, "Help for Overview");
    Box top = Box.createHorizontalBox();
    top.add(activeTiCombo);
    top.add(new JButton(helpAction));

    overview = new Overview(overviewInfoProvider, fltm, curationData, ctm, infoLabel);
    overview.setActiveTraitInstance(fvsm.getActiveTraitInstance(true));
    Container cp = getContentPane();

    cp.add(top, BorderLayout.NORTH);
    //      cp.add(traitLabel, BorderLayout.NORTH);
    cp.add(infoLabel, BorderLayout.SOUTH);
    cp.add(overview, BorderLayout.CENTER);

    pack();
    //      setResizable(false);

    //      setLocationRelativeTo(showOverviewButton);
    // DEFAULT POSITION is "out of the way"
    setVisible(true);

    this.fieldViewSelectionModel.addListSelectionListener(listSelectionListener);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            toFront();
        }

        @Override
        public void windowClosed(WindowEvent e) {
            fieldViewSelectionModel.removeListSelectionListener(listSelectionListener);
            removeWindowListener(this);
        }
    });
}

From source file:components.PasswordDemo.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method should be invoked from the
 * event dispatch thread./*  w  ww . j a v  a 2  s . c o  m*/
 */
private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("PasswordDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Create and set up the content pane.
    final PasswordDemo newContentPane = new PasswordDemo(frame);
    newContentPane.setOpaque(true); //content panes must be opaque
    frame.setContentPane(newContentPane);

    //Make sure the focus goes to the right component
    //whenever the frame is initially given the focus.
    frame.addWindowListener(new WindowAdapter() {
        public void windowActivated(WindowEvent e) {
            newContentPane.resetFocus();
        }
    });

    //Display the window.
    frame.pack();
    frame.setVisible(true);
}

From source file:edu.ku.brc.af.ui.db.ViewBasedDisplayFrame.java

@Override
public void createUI() {
    setBackground(viewBasedPanel.getBackground());

    JScrollPane scrollPane = UIHelper.createScrollPane(viewBasedPanel, true);
    scrollPane.setBorder(BorderFactory.createLineBorder(getBackground(), 8));
    contentPanel = scrollPane;// ww w  . j a v a 2  s  .  com

    super.createUI();

    viewBasedPanel.setOkCancelBtns(okBtn, cancelBtn);

    Integer width = (Integer) UIManager.get("ScrollBar.width");
    if (width == null) {
        width = (new JScrollBar()).getPreferredSize().width;
    }

    Dimension dim1 = getPreferredSize();
    dim1.height += width * 2;
    if (!UIHelper.isMacOS()) {
        dim1.width += width;
    }
    setSize(dim1);

    if (cancelBtn != null) {
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                cancelBtn.doClick();
            }
        });
    } else if (okBtn != null) {
        okBtn.setEnabled(true);
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                okBtn.doClick();
            }
        });
    }

    viewBasedPanel.setOkCancelBtns(okBtn, cancelBtn);

    addAL(okBtn);
    addAL(cancelBtn);
    addAL(applyBtn);
    addAL(helpBtn);
}

From source file:com.tiempometa.muestradatos.JMuestraDatos.java

public JMuestraDatos() {
    initComponents();// w ww.  j  a v  a  2s.  c  om
    this.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent we) {
            int response = JOptionPane.showConfirmDialog(null, "Seguro que deseas cerrar la aplicacin?",
                    "Cerrar Programa", JOptionPane.WARNING_MESSAGE);
            if (response == JOptionPane.YES_OPTION) {
                ReaderContext.stopReading();
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                try {
                    ReaderContext.disconnectUsbReader();
                } catch (ReaderException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                System.exit(0);
            }
        }
    });
    loadSettings();
    if (ReaderContext.getSettings().getDatabaseName() == null) {
        JOptionPane.showMessageDialog(this,
                "No se ha configurado la aplicacin.\nFavor de configurar antes de continuar",
                "Sin configuracin", JOptionPane.WARNING_MESSAGE);
    } else {
        setDatabase(new File(ReaderContext.getSettings().getDatabaseName()));
    }
    ReaderContext.addReadingListener(this);
    ReaderContext.addReaderStatusListener(this);
    Thread thread = new Thread(systemTime);
    thread.start();
}

From source file:JTreeDemo.java

/** Construct the object including its GUI */
public JTreeDemo() {
    super("JTreeDemo");
    Container cp = getContentPane();
    cp.setLayout(new BorderLayout());

    root = new DefaultMutableTreeNode("root");

    child = new DefaultMutableTreeNode("Colors");
    root.add(child);/*from  w  w  w  . java2  s.  com*/
    child.add(new DefaultMutableTreeNode("Cyan"));
    child.add(new DefaultMutableTreeNode("Magenta"));
    child.add(new DefaultMutableTreeNode("Yellow"));
    child.add(new DefaultMutableTreeNode("Black"));

    myTree = new JTree(root);

    // cp.add(BorderLayout.CENTER, myTree);
    //JScrollPane scroller = new JScrollPane();
    //scroller.getViewport().add(myTree);
    JScrollPane scroller = new JScrollPane(myTree);
    cp.add(BorderLayout.CENTER, scroller);

    cp.add(BorderLayout.NORTH, addButton = new JButton("Add"));
    addButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            // Insert more nodes into the tree
            child = new DefaultMutableTreeNode("Flavors");
            child.add(new DefaultMutableTreeNode("Java"));
            child.add(new DefaultMutableTreeNode("Espresso"));
            child.add(new DefaultMutableTreeNode("Hey Joe!"));
            child.add(new DefaultMutableTreeNode("Charcoal"));
            child.add(new DefaultMutableTreeNode("Paint Remover"));

            // Notify the model, which will add it and create an event, and
            // send it up the tree...

            ((DefaultTreeModel) myTree.getModel()).insertNodeInto(child, root, 0);
        }
    });

    cp.add(BorderLayout.SOUTH, quitButton = new JButton("Exit"));
    quitButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setVisible(false);
            dispose();
            System.exit(0);
        }
    });
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            setVisible(false);
            dispose();
            System.exit(0);
        }
    });
    pack();
}