资源简介
SWT表格管理类,包括表头排序事件,table宽度自适应事件,隔行颜色事件
代码片段和文件信息
/**
* 创建:ZhengXi 2009-8-4
*/
package com.infotech.updo.tools;
import java.text.Collator;
import java.util.Locale;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
/**
* SWT表格操作类
* @author 郑曦
*
*/
public class TableManager {
/**
* 为表列添加排序功能
*
* @param table
* 表格
* @param column
* 表列
*/
public static void addSorter(final Table table final TableColumn column) {
column.addListener(SWT.Selection new Listener() {
boolean isAscend = true;
Collator comparator = Collator.getInstance(Locale.getDefault());
public void handleEvent(Event e) {
int columnIndex = getColumnIndex(table column);
TableItem[] items = table.getItems();
for (int i = 1; i < items.length; i++) {
String value2 = items[i].getText(columnIndex);
for (int j = 0; j < i; j++) {
String value1 = items[j].getText(columnIndex);
boolean isLessThan = comparator.compare(value2 value1) < 0;
if ((isAscend && isLessThan)
|| (!isAscend && !isLessThan)) {
String[] values = getTableItemText(table items[i]);
Image image = items[i].getImage();
object obj = items[i].getData();
boolean chck = items[i].getChecked();
items[i].dispose();
TableItem item = new TableItem(table SWT.NONE j);
item.setChecked(chck);
item.setImage(image);
item.setText(values);
item.setData(obj);
items = table.getItems();
break;
}
}
}
table.setSortColumn(column);
table.setSortDirection((isAscend ? SWT.UP : SWT.DOWN)
- 上一篇:基于java swing的多线程电梯调度模拟
- 下一篇:javaWeb学习路线
评论
共有 条评论