Search in sources :

Example 91 with WindowEvent

use of java.awt.event.WindowEvent in project cayenne by apache.

the class ErrorDebugDialog method init.

protected void init() {
    setResizable(false);
    Container pane = this.getContentPane();
    pane.setLayout(new BorderLayout());
    // info area
    JEditorPane infoText = new JEditorPane("text/html", infoHTML());
    infoText.setBackground(pane.getBackground());
    infoText.setEditable(false);
    // popup hyperlinks
    infoText.addHyperlinkListener(this);
    JPanel infoPanel = new JPanel();
    infoPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    infoPanel.add(infoText);
    pane.add(infoPanel, BorderLayout.NORTH);
    // exception area
    if (throwable != null) {
        exText.setEditable(false);
        exText.setLineWrap(true);
        exText.setWrapStyleWord(true);
        exText.setRows(16);
        exText.setColumns(40);
        JScrollPane exScroll = new JScrollPane(exText, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        exPanel = new JPanel();
        exPanel.setLayout(new BorderLayout());
        exPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        exPanel.add(exScroll, BorderLayout.CENTER);
        // buttons
        showHide = new JButton("");
        showHide.addActionListener(this);
        if (isDetailed()) {
            showDetails();
        } else {
            hideDetails();
        }
    }
    close = new JButton("Close");
    close.addActionListener(this);
    JButton[] buttons = (showHide != null) ? new JButton[] { showHide, close } : new JButton[] { close };
    pane.add(PanelFactory.createButtonPanel(buttons), BorderLayout.SOUTH);
    // add a listener to clear static variables, not to produce garbage
    addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            instance = null;
        }
    });
    // prepare to display
    this.pack();
    this.centerWindow();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) Container(java.awt.Container) BorderLayout(java.awt.BorderLayout) WindowEvent(java.awt.event.WindowEvent) JEditorPane(javax.swing.JEditorPane) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter)

Example 92 with WindowEvent

use of java.awt.event.WindowEvent in project knime-core by knime.

the class NodeDialog method initDialog.

/*
     * Inits the underlying dialog with title and icon.
     */
private JDialog initDialog(final String title) {
    JFrame dummy = new JFrame();
    if (KNIMEConstants.KNIME16X16 != null) {
        dummy.setIconImage(KNIMEConstants.KNIME16X16.getImage());
    }
    // init underlying dialog
    JDialog dialog = new JDialog(dummy);
    dialog.setTitle(title);
    dialog.setModal(true);
    // dialog.setResizable(false);
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {

        /**
         * Invoked when the window close icon X is pressed.
         */
        @Override
        public void windowClosed(final WindowEvent e) {
            onClose(e);
        }

        /**
         * Invoked when the window is opened.
         */
        @Override
        public void windowOpened(final WindowEvent we) {
            onOpen(we);
        }
    });
    return dialog;
}
Also used : JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) JDialog(javax.swing.JDialog)

Example 93 with WindowEvent

use of java.awt.event.WindowEvent in project eclipse.platform.swt by eclipse.

the class Bug306490_SwingDisposeError method createSwing.

static void createSwing() {
    JFrame frame = new JFrame("Swing, close me (before or after closing the other window)");
    frame.setBounds(0, 0, 600, 100);
    frame.addWindowListener(new // same bug with using setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE) instead
    WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            e.getWindow().dispose();
            System.out.println("Swing: disposed");
        }
    });
    // remark 1: comment out the following line (do not add textArea) and all works fine
    frame.getContentPane().add(new JTextArea());
    frame.setVisible(true);
}
Also used : JTextArea(javax.swing.JTextArea) JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent)

Example 94 with WindowEvent

use of java.awt.event.WindowEvent in project vcell by virtualcell.

the class ExpressionCanvas method main.

/**
 * main entrypoint - starts the part when it is run as an application
 * @param args java.lang.String[]
 */
public static void main(String[] args) {
    try {
        JFrame frame = new JFrame();
        ExpressionCanvas aExpressionCanvas;
        aExpressionCanvas = new ExpressionCanvas();
        frame.setContentPane(aExpressionCanvas);
        frame.setSize(aExpressionCanvas.getSize());
        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        frame.setVisible(true);
        Insets insets = frame.getInsets();
        frame.setSize(frame.getWidth() + insets.left + insets.right, frame.getHeight() + insets.top + insets.bottom);
        frame.setVisible(true);
    } catch (Throwable exception) {
        System.err.println("Exception occurred in main() of javax.swing.JPanel");
        exception.printStackTrace(System.out);
    }
}
Also used : Insets(java.awt.Insets) JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Example 95 with WindowEvent

use of java.awt.event.WindowEvent in project vcell by virtualcell.

the class BeanUtils method addCloseWindowKeyboardAction.

public static void addCloseWindowKeyboardAction(JComponent jComponent) {
    @SuppressWarnings("serial") Action winCloseAction = new AbstractAction() {

        @Override
        public synchronized void actionPerformed(ActionEvent e) {
            Window window = null;
            if (e.getSource() != null) {
                if (e.getSource() instanceof Window) {
                    window = (Window) e.getSource();
                } else {
                    window = (Window) BeanUtils.findTypeParentOfComponent((Component) e.getSource(), Window.class);
                }
            }
            if (window != null) {
                window.dispatchEvent(new WindowEvent(window, java.awt.event.WindowEvent.WINDOW_CLOSING));
            }
        }
    };
    final String winCloseInputMapAction = "winCloseAction";
    InputMap inputMap = jComponent.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    if (inputMap.get(CLOSE_WINDOW_KEY_STROKE) == null) {
        inputMap.put(CLOSE_WINDOW_KEY_STROKE, winCloseInputMapAction);
        jComponent.getActionMap().put(winCloseInputMapAction, winCloseAction);
    }
}
Also used : Window(java.awt.Window) AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) ActionEvent(java.awt.event.ActionEvent) WindowEvent(java.awt.event.WindowEvent) InputMap(javax.swing.InputMap) AbstractAction(javax.swing.AbstractAction)

Aggregations

WindowEvent (java.awt.event.WindowEvent)201 WindowAdapter (java.awt.event.WindowAdapter)140 JPanel (javax.swing.JPanel)44 JButton (javax.swing.JButton)40 JFrame (javax.swing.JFrame)40 BorderLayout (java.awt.BorderLayout)36 ActionEvent (java.awt.event.ActionEvent)34 Dimension (java.awt.Dimension)32 JLabel (javax.swing.JLabel)30 JScrollPane (javax.swing.JScrollPane)26 ActionListener (java.awt.event.ActionListener)25 GridBagConstraints (java.awt.GridBagConstraints)19 GridBagLayout (java.awt.GridBagLayout)19 FlowLayout (java.awt.FlowLayout)18 Frame (java.awt.Frame)15 Insets (java.awt.Insets)15 JDialog (javax.swing.JDialog)13 JTextArea (javax.swing.JTextArea)13 Container (java.awt.Container)12 WindowListener (java.awt.event.WindowListener)10