How do I resize the dropdown of a combobox?

Dirk picture Dirk · Nov 18, 2010 · Viewed 8.8k times · Source

Background: I am doing some UI work in an eclipse environment where I fill a combo control with some values. The string values have an different length and often a length greater than the combo width and the width of the parent composite.

Problem: When I open the dropdown list, the width of the list is greater than the width of the parent composite and the user could not see the complete value of the list entry.

I have tried to use the "setTextLimit" option, but without success. For me it is perfectly adequate if I could set the width of the dropdon list with a constant value.

Code example:

this.mComponentName = new Combo (lComponentComposite, SWT.BORDER);  
this.mComponentName.setTextLimit(COMBO_TEXT_LIMIT); 
GridData componentNameGridData = new GridData();
componentNameGridData.widthHint = 166;
this.mComponentName.setLayoutData(componentNameGridData);
this.mComponentName.addSelectionListener(this.mComboSelectionAdapter);
this.mComponentName.addKeyListener(this.mComboKeyAdapter);

Greetings dirk

Answer

codejammer picture codejammer · Feb 28, 2012

While creating a combobox specify Horizontal scroll also

this.mComponentName = new Combo (lComponentComposite, SWT.BORDER|SWT.H_SCROLL);  

This will not let the text overflow