본문 바로가기
IT/JAVA & Eclipse

TreeViewer 컬럼 사이즈를 데이터에 맞춰서 resize하기

by 네야나라 2015. 9. 17.
반응형
investorTree.addListener(SWT.Collapse, new Listener(){
   @Override
   public void handleEvent(Event e) {
    expandAndResize(false, (TreeItem) e.item);
   }
  });

  investorTree.addListener(SWT.Expand, new Listener() {
   @Override
   public void handleEvent(Event event) {
    expandAndResize(false, (TreeItem) event.item);
   }
  });

 private static void expandAndResize(Boolean expand_, TreeItem item_)
 {
  System.out.println( (expand_?"Expanding":"Collapsing") + "item={" + item_ + "}");
  item_.setExpanded(expand_);
  System.out.println(" Resizing columns");
  resizeTree(item_.getParent());
 }

 private static void resizeTree(Tree tree_)
 {
  for (TreeColumn tc: tree_.getColumns())
   resizeTreeColumn(tc);
 }

 private static void resizeTreeColumn(TreeColumn treeColumn_)
 {
  treeColumn_.pack();  
 }



반응형