Search code examples
javacomboboxresizeswtdropdown

How to show the maximum number of data into swt combobox?


My SWT Combo has a lot of items and the dropdownlist always shows more data at the same time in linux platform based on display size. (yes I can scroll up and down to see all the other items)

I want the dropdown list to show items at the same time e.g. 10 items at the same time.

I used this code:

m_comboBoxViewer.getCCombo().setVisibleItemCount(10);

I am getting this exception:

org.eclipse.core.runtime.AssertionFailedException: null argument:
    at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:85)
    at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:73)
    at org.eclipse.jface.viewers.ComboViewer.getCCombo(ComboViewer.java:182)

How can I make the dropdown list, to show limited items at the same time? Has anyone an example?


Solution

  • It looks like you are using a ComboViewer which is using a Combo control. You must use a CCombo control to be able to set the visible items count.

    CCombo comboBox = new CCombo(parent, ... style flags ....);
    m_comboBoxViewer = new ComboViewer(comboBox);