Title: RE: Modal JInternalFrames

There is a solution for this by using a GlassPane, yes. My implementation does not work perfect, though, but you could try this code  and perhaps improve it by yourself... (I have not had the time to fix it myself, lately)

/ Henrik

 public ProGlassPane()
   {
      super();
      this.setCursor(Cursor.getPredefinedCursor (Cursor.WAIT_CURSOR));
      setOpaque(false);

      addMouseListener(new MouseAdapter()
      {});
   }

   /**
   * Override setVisible to install/remove key events hook that will allow us to
   * disable key events when the glass pane is visible.
   */
   public void setVisible(boolean visible)
   {
      // This method is called also when an internal frame is selected (window bar
      // pushed, window resized...) with a visible = true parameter and that makes
      // the functionality to become incorrect and surprising.
      
      if (visible)
      {
         if (this.parentWindow == null)
            this.parentWindow = Global.getProInternalFrameForComponent(this);
//            this.parentWindow = SwingUtilities.windowForComponent(this);

         Toolkit.getDefaultToolkit().addAWTEventListener (this, AWTEvent.KEY_EVENT_MASK);
         //this.parentWindow.addAWTEventListener (this, AWTEvent.KEY_EVENT_MASK);
      }
      else
      {
         Toolkit.getDefaultToolkit().removeAWTEventListener (this);
      }
      super.setVisible(visible);
   }

   /**
   * Called whenever there is an event in AWT queue. Note that the current implementation
   * skips all key events, not just events for this window. Logic can be enhanced to examine
   * the source of the event and it's parent window and skip only those events
   * that originated from disabled window
   */
   public void eventDispatched(AWTEvent event)
   {
      if (event instanceof KeyEvent && event.getSource() instanceof Component)
      {
//         if (SwingUtilities.windowForComponent((Component) event.getSource()) == this.parentWindow)
         if (Global.getProInternalFrameForComponent((Component) event.getSource()) == this.parentWindow)
         // Consume events only for our window
         ((KeyEvent)event).consume();
      }
   }

Henrik Johansson
IT Consultant
Pro:Con Sweden
Kyrkogatan 21
S-302 42  HALMSTAD
phone +46 35 16 14 00
direct  +46 35 16 14 08
fax      +46 35 16 14 14
[EMAIL PROTECTED]        
http://www.procon.dk


    -----Original Message-----
    From:   Geert Van Landeghem [SMTP:[EMAIL PROTECTED]]
    Sent:   den 5 mars 2001 11:45
    To:     JAVA SWING EOS (E-mail)
    Subject:        Modal JInternalFrames

    Hi,

    Does anybody know how to make a JInternalFrame modal?

    I've heard about a solution by using a GlassPane or by subclassing
    SystemEventQueue?

    If possible can you direct me to some sources or examples

    Thanks in advance

    ----------------------------------------------------------------------------
    ----------
    Geert Van Landeghem
    Reynders Etiketten
    [EMAIL PROTECTED] (Office)
    [EMAIL PROTECTED] (Home)
    03/460.32.81 (Office)
    0477/759.533 (GSM)

    <<Journey of thousand miles begins with first step>>
    ----------------------------------------------------------------------------
    ----------



    _______________________________________________
    Swing mailing list
    [EMAIL PROTECTED]
    http://eos.dk/mailman/listinfo/swing

Reply via email to