Example usage for java.awt Frame setEnabled

List of usage examples for java.awt Frame setEnabled

Introduction

In this page you can find the example usage for java.awt Frame setEnabled.

Prototype

public void setEnabled(boolean b) 

Source Link

Document

Enables or disables this component, depending on the value of the parameter b .

Usage

From source file:ModalFrameUtil.java

public static void showAsModal(final Frame frame, final Frame owner) {
    frame.addWindowListener(new WindowAdapter() {
        public void windowOpened(WindowEvent e) {
            owner.setEnabled(false);
        }/*from  w w  w  .  ja  v a 2 s . c  o m*/

        public void windowClosing(WindowEvent e) {
            owner.setEnabled(true);
            frame.removeWindowListener(this);
        }

        public void windowClosed(WindowEvent e) {
            owner.setEnabled(true);
            frame.removeWindowListener(this);
        }
    });

    owner.addWindowListener(new WindowAdapter() {
        public void windowActivated(WindowEvent e) {
            if (frame.isShowing()) {
                frame.setExtendedState(JFrame.NORMAL);
                frame.toFront();
            } else {
                owner.removeWindowListener(this);
            }
        }
    });

    frame.setVisible(true);
    try {
        new EventPump(frame).start();
    } catch (Throwable throwable) {
        throw new RuntimeException(throwable);
    }
}