Jan 31

You cannot have a modal JFrame. Use a JDialog if you need a modal window.

written by objects \\ tags: , ,


One Response to “How to create modal JFrame?”

  1. Dmitry Says:

    We can have modal Internal Frame !
    Worked example:
    private synchronized void startModal() {
    try {
    Object obj = AccessController.doPrivileged(new ModalPrivilegedAction(Container.class, “startLWModal”));
    if (obj != null) {
    ((Method) obj).invoke(this, (Object[]) null);
    }

    if (innerDialog || optionPainOpened) {
    // Blocking the thread in case of nested dialogs
    if (SwingUtilities.isEventDispatchThread()) {
    EventQueue theQueue = getToolkit().getSystemEventQueue();
    while (isVisible()) {
    AWTEvent event = theQueue.getNextEvent();
    Object source = event.getSource();

    if (event instanceof ActiveEvent) {
    ((ActiveEvent) event).dispatch();
    }
    else if (source instanceof Component) {
    ((Component) source).dispatchEvent(event);
    }
    else if (source instanceof MenuComponent) {
    ((MenuComponent) source).dispatchEvent(event);
    }
    else {
    System.err.println(“Unable to dispatch: ” + event);
    }
    }
    }
    }
    }
    catch (Exception ex) {
    ex.printStackTrace();
    }
    }

Leave a Reply

You must be logged in to post a comment.