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

REGRESSION: Unselectable JComboBox after Popupmenu owning a component

XMLWordPrintable



      Name: jk109818 Date: 03/14/2002


      FULL PRODUCT VERSION :
      java version "1.4.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
      Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

      FULL OPERATING SYSTEM VERSION :
      Windows XP

      ADDITIONAL OPERATING SYSTEMS :
      Windows 2000 Version 5.00
      Windows 98 Version 4.10

      Windows NT Version 4 (SP 6)

      A DESCRIPTION OF THE PROBLEM :
      This problem occurs on Window XP, NT 2000 and Windows 98
      operating systems. It does not occur on NT4.

      This problem occurs with the Look and Feel Windows (NOT
      ClassicWindows) only.

      After showing a popup menu owning a focusable component,
      selecting an item from a drop list belonging to a combo box
      is not possible anymore. As well, clicking the combobox
      scrollbar causes the combobox to be closed.

      NOTE: Many bug reports turn around this issue, including the
      4168483, but all of them are closed though the bug is still
      there or has reappeared !!

      Best regards,
      Jean-Bernard

      REGRESSION. Last worked in version 1.3.1

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Select an item from the combobox to see if everything is
      okay.
      2. Click on the "click here..." text to open a popup menu.
      3. Reselect an item from the combobox, or click on the
      combobox scrollbar. Items are not selectable anymore, and
      the combobox is closed immediately.
      4. To test the workaround, you may select the "apply work
      around" check box. In this case, everything works fine.

      Best regards,
      Jean-Bernard

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      The combobox items should be selectable, it does not happen
      if you do not use the workaround.

      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      /**
       * ComboBox1Merlin.java
       */
      import java.lang.*;
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.event.*;

      /**
       * Class: ComboBox1Merlin
       */
      public class ComboBox1Merlin extends javax.swing.JFrame
         {
          JPopupMenu popupMenu;
          static boolean workaround = false;
          /**
           * Constructor: ComboBox1Merlin
           * @return instance of ComboBox1Merlin
           */
          public ComboBox1Merlin()
             {
              super();

              final JPanel panel = new JPanel();

              final JTextArea ppFocusItem = new JTextArea();
              /* Bean Properties */
              ppFocusItem.setName("JTextArea");
              ppFocusItem.setLineWrap(true);
              ppFocusItem.setRows(5);
              ppFocusItem.setWrapStyleWord(true);
              ppFocusItem.setMargin(new Insets(2,4,2,4));
              
              /* JPopupMenu */
              popupMenu = new JPopupMenu();
              /* Adds Child */
              popupMenu.add(new JScrollPane(ppFocusItem));

              final JLabel label = new JLabel();
              /* JLabel - Bean Properties */
              label.setText("Click here...");
              label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
              javax.swing.border.EtchedBorder border;
              int bevelType = javax.swing.border.EtchedBorder.LOWERED;
              border = new javax.swing.border.EtchedBorder(bevelType,null,null);
              label.setBorder(new
      javax.swing.border.CompoundBorder(popupMenu.getBorder(),border));
              /* JLabel - sets Bounds */
              label.setBounds(30,100,120,24);
              label.addMouseListener(new java.awt.event.MouseAdapter()
                {
                 public void mousePressed(java.awt.event.MouseEvent e)
                    {
                     Point p = label.getLocation();
                     popupMenu.show(panel,p.x,p.y+label.getHeight());
                     ppFocusItem.requestFocus();
                    }
                });

              final JComboBox comboBox = new JComboBox()
                 {
                  public void updateUI()
                     {
                      super.updateUI();
                      if (workaround &&
      System.getProperty("java.version").compareTo("1.4.0") == 0)
                         { // A workaround. patch 1.4.0 //
                          if (UIManager.getLookAndFeel() instanceof
      com.sun.java.swing.plaf.windows.WindowsLookAndFeel)
                             {
                              com.sun.java.swing.plaf.windows.WindowsLookAndFeel ln =
      (com.sun.java.swing.plaf.windows.WindowsLookAndFeel)UIManager.getLookAndFeel();
                              if (!ln.isClassicWindows())
                                 {
                                  setLightWeightPopupEnabled(false);
                                  return;
                                 }
                             }
                          setLightWeightPopupEnabled(true);
                         }
                     }
                 };
              /* JComboBox - Bean Properties */
              comboBox.setName("JComboBox");
              /* JComboBox - sets Bounds */
              comboBox.setBounds(30,50,120,22);
              comboBox.setPreferredSize(new java.awt.Dimension(100,22));
              for (int i = 0; i < 20; i++)
                   comboBox.addItem("" + i);
                   
              final JCheckBox checkBox = new JCheckBox();
              checkBox.setText("Apply workaround");
              checkBox.setBounds(30,150,120,22);
              checkBox.addActionListener(new java.awt.event.ActionListener()
                 {
                  public void actionPerformed(java.awt.event.ActionEvent e)
                     {
                      workaround = checkBox.isSelected();
                      if (!workaround)
                          comboBox.setLightWeightPopupEnabled(true);
                      comboBox.updateUI();
                     }
                 });
                       
              /* JPanel - Bean Properties */
              panel.setName("JPanel");
              /* JPanel - set Layout */
              panel.setLayout(null);
              /* JPanel - Adds Child */
              panel.add(comboBox);
              panel.add(label);
              panel.add(checkBox);

              /* javax.swing.JFrame - Bean Properties */
              setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
              setName("JFrame");
              setTitle("Title");
              /* javax.swing.JFrame - sets Bounds */
              setBounds(50,100,300,300);
              /* javax.swing.JFrame - Adds Child */
              getContentPane().add(panel,java.awt.BorderLayout.CENTER);

             } /* End of Constructor: ComboBox1Merlin */

          /**
           * Method: generalHandleException <br>
           * @param java.lang.Throwable exception
           * @return void
           */
          protected void generalHandleException(java.lang.Throwable exc)
             {
              exc.printStackTrace(System.err);
             } /* End of Method: generalHandleException */

          /**
           * Method: main <br>
           * Note: Called only if we're an application. <br>
           * @param java.lang.String[] args the command line arguments
           * @return void
           */
          public static void main(java.lang.String[] args)
             {
              try
                 {
                  /* Set native look and feel */
                  
      javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelC
      lassName());

                  /* Creates new MainObject */
                  ComboBox1Merlin self = new ComboBox1Merlin();
                  self.show();
                 } /* End try */
              catch (java.lang.Throwable exc)
                 {
                  exc.printStackTrace(System.err);
                 } /* End catch */
             } /* End of Method: main */

         } /* End of Class: ComboBox1Merlin */



      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      The WorkAround consists in the fact that the JCombobox sets
      LightWeightPopupEnabled according with the other PopupMenus
      factory for the current LookAndFeel.

      JComboBox comboBox = new JComboBox()
         {
          public void updateUI()
             {
              super.updateUI();
              if
      (System.getProperty("java.version").compareTo("1.4.0") == 0)
                 { // A workaround. patch 1.4.0 //
                  if (UIManager.getLookAndFeel() instanceof
      com.sun.java.swing.plaf.windows.WindowsLookAndFeel)
                     {
                      
      com.sun.java.swing.plaf.windows.WindowsLookAndFeel ln =
      (com.sun.java.swing.plaf.windows.WindowsLookAndFeel)UIManage
      r.getLookAndFeel();
                      if (!ln.isClassicWindows())
                         {
                          setLightWeightPopupEnabled(false);
                          return;
                         }
                     }
                  setLightWeightPopupEnabled(true);
                 }
             }
         };

      Release Regression From : 1.3.1
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

      (Review ID: 143968)
      ======================================================================

            kizune Alexander Zuev
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: