Difficulty with jface ComboViewer, need help

I have a Comboviewer object for which I am adding a list with two values: Type1 and Type2.

But when displayed, it displays as: [Type1, Type2] instead of: Type1, then below that Type2.

And I want the first one to be selected by default.

help is needed. thank

+3
source share
1 answer

Use ArrayContentProvider and set the ComboViewer input as an array or list to display a list of items. Define toString () for the item type or provide a LabelProvider object with setLabelProvider () to control the text displayed for each item in the combo.

class Type
{
    private final String    m_name;

    Type(String name)
    {
        m_name = name;
    }

    public String toString()
    {
        return "Type " + m_name;
    }
}

Type type1 = new Type("1");
Type type2 = new Type("2");
ComboViewer comboViewer = new ComboViewer(combo);
comboViewer.setContentProvider(new ArrayContentProvider());
comboViewer.setInput(new Type[] {type1, type2};
comboViewer.setSelection(new StructuredSelection(type1));
+3
source

Source: https://habr.com/ru/post/1733893/


All Articles