花開(kāi)有時(shí)

          花開(kāi)有時(shí),花落有時(shí),來(lái)有時(shí),去有時(shí)。不撕扯,只關(guān)切;不紀(jì)念,只牽掛;不感動(dòng),只明白;不尋找,只記得。
          隨筆 - 24, 文章 - 0, 評(píng)論 - 54, 引用 - 0
          數(shù)據(jù)加載中……

          如何自定義SWT Table的每一個(gè)Cell的height and width

          demonstration code:
          Display display = new Display();
          Shell shell = new Shell(display);
          shell.setBounds(10,10,200,250);
          final Table table = new Table(shell, SWT.NONE);
          table.setBounds(10,10,150,200);
          table.setLinesVisible(true);
          for (int i = 0; i < 5; i++) {
          new TableItem(table, SWT.NONE).setText("item " + i);
          }
          table.addListener(SWT.MeasureItem, new Listener() { 
          public void handleEvent(Event event) { 
          int clientWidth = table.getClientArea().width;
          event.height = event.gc.getFontMetrics().getHeight() * 2; 
          event.width = clientWidth * 2; 
           } 
          });  
          shell.open();
          while (!shell.isDisposed()) {
          if (!display.readAndDispatch()) display.sleep();
          }
          display.dispose();
          

          說(shuō)明:黑體部分是關(guān)鍵,主要是要為table添加一個(gè)監(jiān)聽(tīng)器并要用到SWT.MeasureItem屬性,如果是在TableView下則需要調(diào)用TableView#getTable()方法獲得Table再添加監(jiān)聽(tīng)器。
          還需要注意的是:
          1)這個(gè)特性可能只在Eclipse3.2以上的版本中才有。
          2)不能對(duì)單行(Item)進(jìn)行height的設(shè)置。
          3)如果設(shè)置了width,則column的width以它為準(zhǔn)。
          參考文章:[[1]]http://www.eclipse.org/articles/Article-CustomDrawingTableAndTreeItems/customDraw.htm#_tb10D

          posted on 2008-02-03 16:26 花開(kāi)有時(shí) 閱讀(2411) 評(píng)論(1)  編輯  收藏 所屬分類: Eclipse

          評(píng)論

          # re: 如何自定義SWT Table的每一個(gè)Cell的height and width  回復(fù)  更多評(píng)論   

          非常 不錯(cuò)呀。收藏
          2008-02-17 12:34 | 91cn99
          主站蜘蛛池模板: 高密市| 临沧市| 鄯善县| 湘乡市| 恩施市| 抚松县| 延边| 修武县| 土默特右旗| 麦盖提县| 屯门区| 通辽市| 松阳县| 嵊泗县| 郸城县| 织金县| 米脂县| 乌鲁木齐县| 锡林郭勒盟| 永泰县| 洪江市| 淮北市| 农安县| 临潭县| 博罗县| 信丰县| 铜陵市| 新晃| 永丰县| 大化| 德兴市| 板桥市| 察隅县| 永嘉县| 西和县| 怀安县| 徐州市| 拉孜县| 鄂托克旗| 武宁县| 富民县|