Sorting swt中带组合框的升序-降序表列?
我正在创建EclipseRCP应用程序并使用SWT表,我正在尝试升序和降序列值,但不在列中工作,shell值没有更改,所以请帮助我 我的列值(单元格值)是组合框,如何对我的表中的列组合值进行排序。Sorting swt中带组合框的升序-降序表列?,sorting,combobox,swt,eclipse-rcp,jface,Sorting,Combobox,Swt,Eclipse Rcp,Jface,我正在创建EclipseRCP应用程序并使用SWT表,我正在尝试升序和降序列值,但不在列中工作,shell值没有更改,所以请帮助我 我的列值(单元格值)是组合框,如何对我的表中的列组合值进行排序。公共静态void main(字符串[]args){ public static void main(String[] args) { int size = 5; Random random = new Random(); final int[][] data = new in
公共静态void main(字符串[]args){
public static void main(String[] args) {
int size = 5;
Random random = new Random();
final int[][] data = new int[size][];
for (int i = 0; i < data.length; i++) {
data[i] = new int[] { i, random.nextInt() };
}
// create a virtual table to display data
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final Table table = new Table(shell, SWT.VIRTUAL);
table.setHeaderVisible(true);
table.setLinesVisible(true);
table.setItemCount(size);
final TableColumn column1 = new TableColumn(table, SWT.NONE);
column1.setText("Key");
column1.setWidth(200);
final TableColumn column2 = new TableColumn(table, SWT.NONE);
column2.setText("Value");
column2.setWidth(200);
table.addListener(SWT.SetData, new Listener() {
public void handleEvent(Event e) {
TableEditor fd_editor = new TableEditor(table);
fd_editor.grabHorizontal = true;
CCombo combo = new CCombo(table, SWT.CHECK);
combo.add("ABC");
combo.add("XYZ");
combo.add("PQR");
combo.add("BABA");
combo.add("PAVAN");
combo.add("RAJA");
combo.select(1);
TableItem item = (TableItem) e.item;
int index = table.indexOf(item);
int[] datum = data[index];
item.setText(0, Integer.toString(datum[0]));
fd_editor.setEditor(combo, item, 1);
}
});
// Add sort indicator and sort data when column selected
Listener sortListener = new Listener() {
public void handleEvent(Event e) {
// determine new sort column and direction
TableColumn sortColumn = table.getSortColumn();
TableColumn currentColumn = (TableColumn) e.widget;
int dir = table.getSortDirection();
if (sortColumn == currentColumn) {
dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
} else {
table.setSortColumn(currentColumn);
dir = SWT.UP;
}
// sort the data based on column and direction
final int index = currentColumn == column1 ? 0 : 1;
final int direction = dir;
Arrays.sort(data, new Comparator() {
public int compare(Object arg0, Object arg1) {
int[] a = (int[]) arg0;
int[] b = (int[]) arg1;
if (a[index] == b[index])
return 0;
if (direction == SWT.UP) {
return a[index] < b[index] ? -1 : 1;
}
return a[index] < b[index] ? 1 : -1;
}
});
// update data displayed in table
table.setSortDirection(dir);
table.clearAll();
}
};
column1.addListener(SWT.Selection, sortListener);
column2.addListener(SWT.Selection, sortListener);
table.setSortColumn(column1);
table.setSortColumn(column2);
table.setSortDirection(SWT.DOWN);
shell.setSize(shell.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, 500);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
int size=5;
随机=新随机();
最终整数[]数据=新整数[大小][];
对于(int i=0;i
Hi sir我收到了我的密码,请帮助我解决问题。这应该是问题的一部分,而不是答案。