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

IllegalComponentStateException is thrown when JComboBox lw popup menu is used

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.7, 1.2.0
    • client-libs
    • generic, x86
    • generic, windows_95


      An IllegalComponentStateException is often thrown when switching
      between lightweight and heavyweight popup menu of JComboBox:
      Exception occurred during event dispatching:
      java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location
              at java.awt.Component.getLocationOnScreen(Compiled Code)
              at java.awt.LightweightDispatcher.eventDispatched(Compiled Code)
              at java.awt.Toolkit$SelectiveAWTEventListener.eventDispatched(Compiled Code)
              at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Compiled Code)
              at java.awt.Toolkit.notifyAWTEventListeners(Compiled Code)
              at java.awt.Component.dispatchEventImpl(Compiled Code)
              at java.awt.Container.dispatchEventImpl(Compiled Code)
              at java.awt.Component.dispatchEvent(Compiled Code)
              at java.awt.LightweightDispatcher.retargetMouseEvent(Compiled Code)
              at java.awt.LightweightDispatcher.processMouseEvent(Compiled Code)
              at java.awt.LightweightDispatcher.dispatchEvent(Compiled Code)
              at java.awt.Container.dispatchEventImpl(Compiled Code)
              at java.awt.Window.dispatchEventImpl(Compiled Code)
              at java.awt.Component.dispatchEvent(Compiled Code)
              at java.awt.EventQueue.dispatchEvent(Compiled Code)
              at java.awt.EventDispatchThread.run(Compiled Code)



      To recreate this, bring up the following application and do the
      following:
      - Pop up the combo box, select an item
      - De-select the "LightWeightPopup enabled" checkbox
      - Pop up the combo box, select an item
      - Select the "LightWeightPopup enabled" checkbox
      - Pop up the combo box, and attempt to use the scrollbar of the
        popup menu

      This causes the IllegalComponentStateException to be thrown.

      =========================================================================
      /*
       * JComboBoxTest.java
       * IllegalComponentStateException is often thrown when switching
       * between lightweight and heavyweight popup menu for JComboBox
       *
      */

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

      public class JComboBoxTest extends JFrame implements ActionListener {
          JComboBox combobox;
          JCheckBox lwpopup;
          JPanel infoPanel = new JPanel();
          JPanel p1 = new JPanel();
          JPanel p2 = new JPanel();

          public JComboBoxTest() {
              Container c = getContentPane();
      c.setLayout(new BorderLayout());
      infoPanel.setLayout(new GridLayout(0,1));
              infoPanel.add(new JLabel("IllegalComponentStateException is often thrown when switching"));
              infoPanel.add(new JLabel("between lightweight and heavyweight popup menu of JComboBox."));
              infoPanel.add(new JLabel("Click \"LightWeightPopup enabled\" checkbox to invoke setLightWeightPopupEnabled()."));
              infoPanel.add(new JLabel("Switch between lightweight and heavyweight popup menu a few times,"));
              infoPanel.add(new JLabel("then use the popup menu's scrollbar."));
              infoPanel.add(new JLabel("This often causes an IllegalComponentStateException."));
              c.add(BorderLayout.NORTH, infoPanel);

              combobox = new JComboBox();
              for(int i = 0; i < 25; i++) {
                combobox.addItem("Row " + i);
              }

              p1.add(combobox);
              c.add(BorderLayout.CENTER, p1);
              lwpopup = new JCheckBox("LightWeightPopup enabled");
              lwpopup.setSelected(combobox.isLightWeightPopupEnabled());
              lwpopup.setToolTipText("Invokes setLightWeightPopupEnabled().");
              lwpopup.addActionListener(this);
              p2.add(lwpopup);
              p2.setBackground(Color.pink);

              c.add(BorderLayout.SOUTH, p2);
          }

          public static void main(String argv[]) {
              JFrame frame = new JComboBoxTest();
      frame.setTitle("JComboBox.setLightWeightPopupEnabled() Test");
      frame.pack();
      frame.setSize(700,400);
      frame.setVisible(true);
          }

          public void actionPerformed(ActionEvent e) {
      if (e.getSource() == lwpopup) {
                combobox.setLightWeightPopupEnabled(lwpopup.isSelected());
      }
          }
      }
      =========================================================================

            rkhansunw Robi Khan (Inactive)
            gaurisha Gauri Sharma (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: