Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I resize the dropdown of a combobox?

Tags:

java

combobox

swt

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

like image 434
Dirk Avatar asked Nov 18 '10 08:11

Dirk


People also ask

What is the difference between drop-down list and ComboBox?

A drop-down list is a list in which the selected item is always visible, and the others are visible on demand by clicking a drop-down button. A combo box is a combination of a standard list box or a drop-down list and an editable text box, thus allowing users to enter a value that isn't in the list.


2 Answers

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

like image 118
codejammer Avatar answered Oct 17 '22 08:10

codejammer


That is really a good question. After digging through developer forums and even the source code, I lean towards saying it is not possible.

I solved the problem temporarily by switching to a CCombo, but I do not like the solution as I believe one of SWT's strength is in using native widgets, and the CCombo does not look as good (at least on Win7 and OS X).

like image 39
Krumelur Avatar answered Oct 17 '22 09:10

Krumelur