How to add an unselectable separator to a combobox in SWT
Asked Answered
G

1

12

A combobox in our application should show fixed-width and non-fixed-widths font names. I want to add an unselectable separator between them:

-- Fixed-width fonts --
Courier New
Lucida Console
...
-- Non-fixed-width fonts --
Arial
...

Is that possible with SWT?

Granddaddy answered 17/3, 2011 at 13:27 Comment(0)
R
0

The short answer is no. Neither Combo nor CCombo allow to flag items as unselectable.

But it should be possible to implement a custom combo widget that can show unselectable items with reasonable effort.

If you look into the CCombo code you will see that it is not a native widget but composed of other SWT widgets. It uses a List as the drop-down control to display the items.

If you use a ScrolledCompposite for the drop-down widget, you could place Labels therein to represent items. Unselectable items wouldn't require extra work. For selectable items, you could use mouse listeners for the Labels to highlight them when hovered and to handle selection.

If you plan to show a large number of items (which you shouldn't anyway in a combo box), the number of created labels may have a performance impact.

Alternatively, you may want to try the Nebula TableCombo. Possibly the table can be tweaked to show some items as unselectable (using custom-drawn items) and the selection behavior can be disabled for those.

Rhpositive answered 19/7, 2015 at 19:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.