JDK-6248072 : Changing the selection mode of the list introduces an empty item at the end, on win32
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: generic
  • Submitted: 2005-03-30
  • Updated: 2011-03-07
  • Resolved: 2011-03-07
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 7
7 b14Fixed
Related Reports
Relates :  
Description
I am showing a list which is in multi-selection mode initially. Some of the items in the list are selected. I am clicking on a button to toggle the selection mode of the list. Say if the list is in multi-mode, clicking a button would make it single-selection mode and vice versa. When I change from multi-select mode to single select mode, an empty item is appended to the end of the list and clicking on this empty item triggers spurious item events. This is incorrect.

This is reproducible only on Win32 since 1.4.2. Not reproducible on XToolkit. 

I have attached a sample test. Execute it on WinXP. You would see a list. Select few items in the list. Click on the button adjacent to the list. Scroll down to the end of the list. If you see an empty space, the bug is reproduced. Click on the empty space, it will trigger an item event for the currently selected item.
###@###.### 2005-03-30 16:10:58 GMT

Comments
SUGGESTED FIX *** 299,308 **** --- 299,309 ---- RECT rect; GetWindowRect(GetListHandle(), &rect); MapWindowPoints(0, parentHWnd, (LPPOINT)&rect, 2); HANDLE font = (HANDLE)SendListMessage(WM_GETFONT); + LRESULT itemHeight = SendListMessage(LB_GETITEMHEIGHT, 0); DWORD style = ::GetWindowLong(GetListHandle(), GWL_STYLE) | WS_VSCROLL | WS_HSCROLL; if (isMultiSelect) { style |= LBS_MULTIPLESEL; } else { style &= ~LBS_MULTIPLESEL; *** 320,329 **** --- 321,331 ---- ::GetSysColor(COLOR_WINDOWTEXT), ::GetSysColor(COLOR_WINDOW), peer); SendListMessage(WM_SETFONT, (WPARAM)font, (LPARAM)FALSE); + SendListMessage(LB_SETITEMHEIGHT, 0, MAKELPARAM(itemHeight, 0)); SendListMessage(LB_RESETCONTENT); for (i = 0; i < nCount; i++) { InsertString(i, strings[i]); delete [] strings[i]; }
16-05-2007

EVALUATION The cause of the bug is that we don't set height of the items of the list during changing mode (that is recreate) of the list. That's why changing mode of the list cause to the problems like overlapping items, appearing empty space, etc.
15-06-2005