更改swt下拉列表元素顺序

时间:2020-12-30 22:24:50

I am new to SWT, and there is a project which demand me to change the order of element in a drop down list, the list contains data stocking in the database which is ordered by the order alphabet, while I would like to change the order of elements in the drop down list,can somebody tell me how the dropdown list obtain the data list from the database and how to change the order? Thank you very much.

我是SWT的新手,并且有一个项目要求我在下拉列表中更改元素的顺序,该列表包含数据库中的数据库存,该数据库按订单字母表排序,而我想更改订单下拉列表中的元素,有人可以告诉我下拉列表如何从数据库中获取数据列表以及如何更改顺序?非常感谢你。

Here comes the code of creating an object, and I would like to know how to change the order of the list. Thank you.

这里是创建对象的代码,我想知道如何更改列表的顺序。谢谢。

public final Object[] getElements(final Object inputElement) {
    if (inputElement != null) {
        if (inputElement instanceof Test) {
            return getTest((EngdynoRequest) engDynoRequest).toArray();
        }
    }
    return null;
}

3 个解决方案

#1


0  

make your own list of objects, after that you can order it in any way which you need, after that you can make your dropdown list with ordered elements.

制作您自己的对象列表,然后您可以以您需要的任何方式对其进行排序,之后您可以使用有序元素制作下拉列表。

#2


0  

If you have correctly located the method used for populating the combobox you can just sort the list of objects here.

如果您已正确找到用于填充组合框的方法,则可以在此处对对象列表进行排序。

return getTest((EngdynoRequest) engDynoRequest).toArray();

can be replaced with

可以替换为

Object[] unsorted = getTest((EngdynoRequest) engDynoRequest).toArray();
return Arrays.sort(unsorted);

If you want custom sorting order you can pass your own comparator via Arrays.sort

如果您想要自定义排序顺序,可以通过Arrays.sort传递自己的比较器

#3


0  

There are couple of methods on ComboViewer that you may want to look at

您可能想要查看ComboViewer上的几种方法

StructuredViewer.java

public void setComparer(IElementComparer comparer) 

public void setComparator(ViewerComparator comparator)

public void setSorter(ViewerSorter sorter)

#1


0  

make your own list of objects, after that you can order it in any way which you need, after that you can make your dropdown list with ordered elements.

制作您自己的对象列表,然后您可以以您需要的任何方式对其进行排序,之后您可以使用有序元素制作下拉列表。

#2


0  

If you have correctly located the method used for populating the combobox you can just sort the list of objects here.

如果您已正确找到用于填充组合框的方法,则可以在此处对对象列表进行排序。

return getTest((EngdynoRequest) engDynoRequest).toArray();

can be replaced with

可以替换为

Object[] unsorted = getTest((EngdynoRequest) engDynoRequest).toArray();
return Arrays.sort(unsorted);

If you want custom sorting order you can pass your own comparator via Arrays.sort

如果您想要自定义排序顺序,可以通过Arrays.sort传递自己的比较器

#3


0  

There are couple of methods on ComboViewer that you may want to look at

您可能想要查看ComboViewer上的几种方法

StructuredViewer.java

public void setComparer(IElementComparer comparer) 

public void setComparator(ViewerComparator comparator)

public void setSorter(ViewerSorter sorter)