JDK-6239941 : Choice triggers ItemEvent when selecting an item with right mouse button, Xtoolkit
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_9
  • CPU: sparc
  • Submitted: 2005-03-13
  • Updated: 2011-01-19
  • Resolved: 2005-04-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b33Fixed
Related Reports
Relates :  
Description
I am showing a frame with a button and a choice. When I click on the choice using left mouse button, the drop-down appears. Once the drop-down is shown, I am clicking on one of the items using middle / right mouse button. The drop-down disappears and an ItemEvent is triggered for the already selected item (not the item that I selected with right button). This is incorrect. ItemEvent should not be triggered when the user does not select anything or selects something with a right/middle mouse button. 

This is reproducible only on XToolkit, since Tiger. Not reproducible on Motif or Win32. On Win32, nothing happens when clicking the right button. On Motif, the drop-down disappears but no item event is triggered. Reproducible on Mustang-b26. 

I have attached a sample test. Execute the sample test. You would see a choice on a frame. Click on the choice using left button. A drop-down will appear. Click on any of the items using middle/right mouse button. If see an ItemEvent on the console, the bug is reproduced. I tested this on Solaris9-GNOME.
###@###.### 2005-03-13 17:11:56 GMT

Comments
EVALUATION We post ItemEvent when user releases mouse button over the opened Choice. We doesn't check the button that being used. We should make following thing only when user uses LeftMouseButton. postEvent(new ItemEvent((Choice)target, ItemEvent.ITEM_STATE_CHANGED, ((Choice)target).getItem(newIdx), ItemEvent.SELECTED)); ###@###.### 2005-03-23 13:08:40 GMT Some description about fix: --1) we have closed choice. I'll use only LEFTMOUSE button in this case. I'm pressing a LB on it and see that in XChoicePeer.mousePressed: dragStartIdx ==0. Then I'm moving the mouse on Choice's element (different from already having selection) and press LB on it. Now mousePressed() : dragStartIdx ==0 (it returned by ListHelper and since LB was pressed we see that mouse tracking started: trackSelection(x, y) invokes helper.select(nexIdx)) By the time when we release mouse new index already changed. mouseReleased: nexIdx == 8 and dragStartIdx ==0 and we are selecting index 8. --2) I'll use RIGHTBUTTON. After pressing a LEFTMOUSE on closed Choice we have mousePressed: drahStartIdx==0 now press RIGHTMOUSE on other Choice's item we note that mousePressed: dragStartIdx ==0 but we will not initiate mouse tracking since it starts only if we press LEFTBUTTON. Finally, in mouseReleased newIdx == 0 and dragStartIdx ==0 and we will not initiate ItemEvent. So, there is no ItemEvent occur if we press RB because pressing RB wasn't initiated XChoicePeer.mousePressed().unfurledChoice.trackMouse(e) where we change current selected index. ###@###.### 2005-03-25 09:51:24 GMT
23-03-2005

SUGGESTED FIX *** /tmp/geta7111 23 16:07:28 2005 --- XChoicePeer.java 23 16:06:58 2005 *************** *** 362,371 **** // NOTE: We get a repaint when Choice.select() // calls our peer.select(). } ! postEvent(new ItemEvent((Choice)target, ! ItemEvent.ITEM_STATE_CHANGED, ! ((Choice)target).getItem(newIdx), ! ItemEvent.SELECTED)); } } else { --- 362,376 ---- // NOTE: We get a repaint when Choice.select() // calls our peer.select(). } ! /*fix for 6239941 : Choice triggers ItemEvent when selecting an item with right mouse button, Xtoolkit ! * We should generate ItemEvent if only ! * LeftMouseButton used */ ! if (e.getButton() == MouseEvent.BUTTON1){ ! postEvent(new ItemEvent((Choice)target, ! ItemEvent.ITEM_STATE_CHANGED, ! ((Choice)target).getItem(newIdx), ! ItemEvent.SELECTED)); ! } } } else { ###@###.### 2005-03-23 13:08:40 GMT
23-03-2005