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

Use JComboBox as it's own ActionListener leads to unexpected behaviour

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b22
    • OS:
      windows_7

      Backports

        Description

        FULL PRODUCT VERSION :
        1.7.0_06

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows 6.1.7601

        A DESCRIPTION OF THE PROBLEM :
        If you use a JComboBox as it's own ActionListener you will get unexpected behaviour:

        The entries become (visually) unselectable.

        This problem encounters especially when inheriting a class from JComboBox that implements an ActionListener

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. create a (not-empty) JComboBox
        2. use it as it's own ActionListener
        3. add it to a Window/Dialog/Frame/Panel and run it
        4. select an entry, different from the first one

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        An entry should get selected
        ACTUAL -
        No entry is selected

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        public static void main(String[] args) {

        JDialog dialog = new JDialog();

        String[] entries = { " Cats " , " Porn " , " Lazors " , " Memes " };

        // here starts the relevant part
        JComboBox<String> myComboBox = new JComboBox<String>(entries);
        myComboBox.addActionListener(myComboBox);
        // here ends the relevant part

        dialog.add(myComboBox);
        dialog.pack();
        dialog.setVisible(true);

        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        If you need to inherit a class from JComboBox and you want to have it's own Listener, don't use ActionListener, use ItemListener instead.

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                malenkov Sergey Malenkov (Inactive)
                Reporter:
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: