Combo Box with Images in SWT
For past few days I’ve been working on new SWT widget called ComboBoxEx. This widget is capable of displaying items in Combo along with assigned images. At current state it’s more or less completed for Windows (win32) SWT. Code base for this widget is derived from SWT Combo class. Windows widget used in this class has class name “COMBOBOXEX32″ and was introduced long time ago by Internet Explorer 4.0 and is currently available for all Windows versions.
Currently widget is only available on Windows, but I’m planning to provide separate classes for use in other major operating systems (GTK and MacOs) that will encapsulate Combo widget with same interface, e.g. ComboItem instead of String based item.
Here’s the widget example as it is drawn by operating system on Windows XP.

Similar image will be posted for Windows Vista, later today. Here’s an image from Windows Vista.

Code for example shown above:
combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
new ComboItem(combo, "Question Icon 32×32", display.getSystemImage(SWT.ICON_QUESTION), 0);
new ComboItem(combo, "Error Icon 32×32", display.getSystemImage(SWT.ICON_ERROR), 0);
combo.select(0);
Unfortunately this widget has a dependency on Java Native Access library from Sun. Let me explain. OS class that has native method declared doesn’t provide COMBOBOXEXITEM structure and appropriate SendMessage method that takes this structure as a LWORD parameter. Without this changes we’re not able to send COMBOBOXEXITEM structure to underlying widget.
I’ll try to release this widget within 2 weeks first for Windows, after that for other operating systems.
WordPress
Radek Urbas said:
Apr 21, 09 at 21:10Looks great! Waiting for GTK & Cocoa versions ;)
Longyearbyen said:
Apr 23, 09 at 14:35This is really something useful. Maybe you would consider implementing tooltips for the comboItems as well. No tooltips for comboItems suc*!