0

I am looking for a SWT Combo where only dropdown arrow is shown in order to save space.

I found that setting a GridData.widthHint to the width of the arrow icon on the Combo might do the trick.

The question is how do I ask the Combo layout the exact width of the down arrow on the Combo so that I can set that as the widthHint?

enter image description here

Update:

Looks like even setting the widthHint = 0 still shows part of the text field. So any other ideas would be welcome.

2c00L
  • 495
  • 12
  • 29

1 Answers1

3

I don't see a way to get the drop down button width. Messing around with the width hint is likely to be very platform dependent.

An alternative would be to use code similar to the CCombo control but without the Text field. This uses a Button with the SWT.ARROW | SWT.DOWN style:

Button button = new Button(parent, SWT.ARROW | SWT.DOWN);

When the button is pressed an SWT List control is displayed.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • How do I add the list control to this button so that it works the same as a Combo list? – 2c00L Feb 12 '16 at 09:58
  • I am going to add greg's answer to greg's answer :). See [this](http://stackoverflow.com/questions/26101455/how-to-display-a-popup-menu-by-mouse-left-click-in-swt) Add a selection listener to your button that shows the menu. – SomeDude Feb 12 '16 at 17:31