Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4418218

JFrame with a JDialog that uses a JPopupMenu throws exceptions

XMLWordPrintable

    • beta2
    • x86
    • windows_nt



      Name: boT120536 Date: 02/22/2001


      ava version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)




      If JDialog (created with parent JFrame) location over this JFrame,
      so as when JPopupMenu is show (with parent JDialog),
      it body wholly appears above the this JFrame, then exception occurred.
      |----------------------|
      | |------------------| |
      | | |-------------| | |
      | | | | | |
      | | | | | |
      | | | JPopupMenu| | |
      | | |-------------| | |
      | | | |
      | | JDialog | |
      | |------------------| |
      | |
      | JFrame |
      |----------------------|

      If part of JPopupMenu is not appears above the this JFrame, all right.
      |----------------------|
      | |------------------|
      | | |-------------| |
      | | | | |
      | | | | |
      | | | JPopupMenu | |
      | | |-------------| |
      | | |
      | | JDialog |
      | |------------------|
      | |
      | JFrame |
      |----------------------|



      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;

      public class gogi implements ActionListener
      {
          
      static public void main(String args[])
      {
      new gogi();
      }

      JFrame frame = new JFrame("frame");
      JDialog dialog = new JDialog(frame, "dialog");
      JButton button = new JButton("push");
      JPopupMenu popupmenu = new JPopupMenu("pm");

      public gogi(){
      frame.getContentPane().setLayout(null);
      frame.setBounds(100, 100, 300, 300);
      dialog.setBounds(150, 150, 100, 100);
      dialog.setModal(true);
      dialog.setResizable(false);
      dialog.getContentPane().setLayout(new BorderLayout());
      dialog.getContentPane().add("Center", button);
      button.addActionListener(this);
      popupmenu.add(new JMenuItem("1"));
      popupmenu.add(new JMenuItem("2"));
      frame.setVisible(true);
      dialog.setVisible(true);
      }

      public void actionPerformed(ActionEvent e){
      popupmenu.show(dialog, button.getX(), button.getX());
      }
      }


      popupmenu show if it completely does not hit over frame,
      else throw exception

      gogi.class successfully loaded
      Exception occurred during event dispatching:
      java.lang.Error: Do not use javax.swing.JFrame.add() use
      javax.swing.JFrame.getContentPane().add() instead
          at javax.swing.JFrame.createRootPaneException(JFrame.java:333)
          at javax.swing.JFrame.addImpl(JFrame.java:355)
          at java.awt.Container.add(Container.java:210)
          at javax.swing.JPopupMenu$JPanelPopup.show(JPopupMenu.java:1741)
          at javax.swing.JPopupMenu.setVisible(JPopupMenu.java:858)
          at javax.swing.JPopupMenu.show(JPopupMenu.java:981)
          at gogi.actionPerformed(gogi.java:34)
          at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1066)
          at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed
      (AbstractButton.java:1101)
          at javax.swing.DefaultButtonModel.fireActionPerformed
      (DefaultButtonModel.java:378)
          at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250)
          at javax.swing.plaf.basic.BasicButtonListener.mouseReleased
      (BasicButtonListener.java:204)
          at java.awt.Component.processMouseEvent(Component.java:3160)
          at java.awt.Component.processEvent(Component.java:2999)
          at java.awt.Container.processEvent(Container.java:990)
          at java.awt.Component.dispatchEventImpl(Component.java:2394)
          at java.awt.Container.dispatchEventImpl(Container.java:1035)
          at java.awt.Component.dispatchEvent(Component.java:2307)
          at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2043)
          at java.awt.LightweightDispatcher.processMouseEvent(Container.java:1827)
          at java.awt.LightweightDispatcher.dispatchEvent(Container.java:1730)
          at java.awt.Container.dispatchEventImpl(Container.java:1022)
          at java.awt.Window.dispatchEventImpl(Window.java:749)
          at java.awt.Component.dispatchEvent(Component.java:2307)
          at java.awt.EventQueue.dispatchEvent(EventQueue.java:287)
          at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103)
          at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:92)
          at java.awt.EventDispatchThread.run(EventDispatchThread.java:83)
      (Review ID: 117286)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: