分享

TableItem的使用

 桑枯海 2012-03-17
TableItem的使用

TableItem item = new TableItem(table, SWT.NONE);

String[] data = dialog.open();

  item.setText(data);

原来TableItem可以用setText设定多个列.

查看源代码

public void setText (String [] strings) {
 checkWidget();
 if (strings == null) error (SWT.ERROR_NULL_ARGUMENT);
 for (int i=0; i<strings.length; i++) {
  String string = strings [i];
  if (string != null) setText (i, string);
 }
}


原来是根据字符数组的长度来给各个列赋值的.

实际调用的还是setText(int index, String string) 

public void setText (int index, String string) {
 checkWidget();
 if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
 if (index == 0) {
  if (string.equals (text)) return;
  super.setText (string);
 }
 int count = Math.max (1, parent.getColumnCount ());
 if (0 > index || index > count - 1) return;
 if (strings == null && index != 0) strings = new String [count];
 if (strings != null) {
  if (string.equals (strings [index])) return;
  strings [index] = string;
 }
 if (index == 0) {
  /*
  * Bug in Windows.  Despite the fact that every item in the
  * table always has LPSTR_TEXTCALLBACK, Windows caches the
  * bounds for the selected items.  This means that
  * when you change the string to be something else, Windows
  * correctly asks you for the new string but when the item
  * is selected, the selection draws using the bounds of the
  * previous item.  The fix is to reset LPSTR_TEXTCALLBACK
  * even though it has not changed, causing Windows to flush
  * cached bounds.
  */
  if ((parent.style & SWT.VIRTUAL) == 0 && cached) {
   int itemIndex = parent.indexOf (this);
   if (itemIndex != -1) {
    int hwnd = parent.handle;
    LVITEM lvItem = new LVITEM ();
    lvItem.mask = OS.LVIF_TEXT;
    lvItem.iItem = itemIndex;
    lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
    OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem);
    cached = false;
   }
  }
  parent.setScrollWidth (this, false);
 }
 redraw (index, true, false);
}

fengxx 发表于:2005.01.11 13:12

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多