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

awt Choice doesn't fire ItemStateChange when selecting item after select() call

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b61
    • CPU:
      x86
    • OS:
      windows_7
    • Verification:
      Verified

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.7.0_04"
        Java(TM) SE Runtime Environment (build 1.7.0_04-b22)
        Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 6.1.7600]

        A DESCRIPTION OF THE PROBLEM :
        The AWT Choice component no longer fires an ItemStateChange Event when selecting the previously selected item after code call to select(x).

        i.e. we have a Choice with various string values.
        The user selects a value and completes their current task.
        The application clears the selection to a default state by calling Choice.select(0)
        The user then selects the same value that was selected before the select call.
        No ItemStateChange event is fired.

        This meens that it is impossible to clear the state of a screen before additional input.

        REGRESSION. Last worked in version 6u31

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. Run the supplied test class.
        2. Select a value other than blank from the Choice.
        3. A label at the top of the Frame will display the selected value (via the ItemStateChange event)
        4. Click the Button, this will call select(0) on the Choice and clear the Label at the top of the Frame.
        5. Select the same Choice item as in step 2.
        6. Observe that the Label at the top of the Frame does not show the selected Choice value, the ItemStateChange Event was not fired, the ItemListener was not invoked.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        After calling Choice.select(x) and then using the Keyoard or Mouse to reselect the previously selected item, the ItemStateChange Event should be fired!
        ACTUAL -
        Selecting the previously selected item from the Choice after a call to Choice.select(x) does not fire the ItemStateChanged Event

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        public class ChoiceTest extends Panel
        {
        private Choice choice;
        private Button selectBlankBtn;
        private Label status;

        void init()
        {
        setLayout(new BorderLayout());
        add(getChoice(), BorderLayout.CENTER);
        add(getSelectBlankBtn(), BorderLayout.SOUTH);
        add(getStatus(), BorderLayout.NORTH);
        setPreferredSize(new Dimension(100, 100));
        }

        private Label getStatus()
        {
        if (status == null)
        {
        status = new Label("");
        }
        return status;
        }

        private Button getSelectBlankBtn()
        {
        if (selectBlankBtn == null)
        {
        selectBlankBtn = new Button("Select Blank");
        selectBlankBtn.addActionListener(new ActionListener()
        {
        @Override
        public void actionPerformed(ActionEvent e)
        {
        getChoice().select(0);
        getStatus().setText("");
        }
        });
        }
        return selectBlankBtn;
        }

        private Choice getChoice()
        {
        if (choice == null)
        {
        choice = new Choice();
        choice.setPreferredSize(new Dimension(50, 50));
        choice.add(" ");
        choice.add("1");
        choice.add("2");
        choice.add("3");
        choice.addItemListener(new ItemListener()
        {
        @Override
        public void itemStateChanged(ItemEvent e)
        {
        if (e.getStateChange() == ItemEvent.DESELECTED)
        getStatus().setText(String.format("Deselected: %1$s", e.getItem()));
        if (e.getStateChange() == ItemEvent.SELECTED)
        getStatus().setText(String.format("Selected: %1$s", e.getItem()));
        }
        });
        }
        return choice;
        }

        public static void main(String[] args)
        {
        ChoiceTest test = new ChoiceTest();
        test.init();
        final Frame f = new Frame();
        f.setLayout(new GridBagLayout());
        f.add(test);
        f.pack();
        f.setSize(new Dimension(200, 200));
        f.setVisible(true);
        f.addWindowListener(new WindowListener()
        {
        @Override
        public void windowOpened(WindowEvent e)
        {
        }

        @Override
        public void windowIconified(WindowEvent e)
        {
        }

        @Override
        public void windowDeiconified(WindowEvent e)
        {
        }

        @Override
        public void windowDeactivated(WindowEvent e)
        {
        }

        @Override
        public void windowClosing(WindowEvent e)
        {
        f.dispose();
        }

        @Override
        public void windowClosed(WindowEvent e)
        {
        f.setVisible(false);
        }

        @Override
        public void windowActivated(WindowEvent e)
        {
        }
        });
        }
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Unable to find a workaround in code.
        The user can select any other item from the Choice and then reselect the previously selected item in order for the ItemStateChange Event to be fired correctly.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  bagiras Oleg Pekhovskiy (Inactive)
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  4 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: