⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tablemanager.java

📁 一款少见的用swt写的彩票软件
💻 JAVA
字号:
package com.dc.test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

/**
* @author dali
*
*/
public class TableManager {

   private static Map<String, TableManager> tableview = new HashMap<String, TableManager>();

   private Table table = null;

   private TableManager(Table table) {
       this.table = table;
   }

   public static TableManager addTable(String key, Table table) {
       tableview.put(key, new TableManager(table));
       return getTable(key);
   }

   public static TableManager getTable(String key) {
       if (!tableview.containsKey(key))
           tableview.put(key, new TableManager(null));
       return tableview.get(key);
   }

   public void show(List<String[]> list) {
       if(list == null || list.size() == 0) return;
       setTableColumn(list.remove(0));
       table.removeAll();    //清楚上次结果
       showTableItem(list);
   }

   //显示列名称
   public void setTableColumn(String[] column) {
       TableColumn[] tableColumn = new TableColumn[column.length];
       //判断是否以设置过表格列名称
       if("tc".equals(table.getData("tc")))
           return;
       table.setData("tc","tc");
       for (int i = 0; i < column.length; i++) {
           tableColumn[i] = new TableColumn(table, SWT.NONE);
           tableColumn[i].setWidth(80);
           tableColumn[i].setText(column[i]);
       }        
   }

   //显示列数据
   public void showTableItem(List<String[]> item) {
       table.removeAll();
       if(item == null) return;
       TableItem[] tableItem = new TableItem[item.size()];
       for (int i = 0; i < item.size(); i++) {
           tableItem[i] = new TableItem(table,SWT.NONE);
           tableItem[i].setText(item.get(i));
       }
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -