Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT tree: auto resize all columns
SWT tree: auto resize all columns [message #545546] Thu, 08 July 2010 08:39 Go to next message
MadH  is currently offline MadH
Messages: 2
Registered: July 2010
Junior Member
cross-post at stackoverflow

In a tree with multiple columns, how do I resize columns to contents upon expand/collapse and data updates?
The following works works for data updates (by calling the resizeTree), but for expands/collapses it is one step behind! Sad

  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();  
 }



More specifically, if I expand an item in the first column, and the underlying item is longer than the column width, the resize to that width will be done upon a next collapse or expand of some other item (or if I directly call resizeTree()).
Just in case it is important: the data is given by TreeContentProvider and ITableLabelProvider, and my guess is that ITableLabelProvider might cause the problem (the width of the column is adjusted before the label gets generated?! Shocked )

SWT 3.5

[Updated on: Thu, 08 July 2010 08:47]

Report message to a moderator

Re: SWT tree: auto resize all columns [message #546221 is a reply to message #545546] Mon, 12 July 2010 08:31 Go to previous message
MadH  is currently offline MadH
Messages: 2
Registered: July 2010
Junior Member
the solution is to use display.asyncExec( Runnable )
Previous Topic:Listening to checking/unchecking of TableItems
Next Topic:Separate table columns on Mac OS
Goto Forum:
  


Current Time: Sun Oct 26 01:59:48 GMT 2014

Powered by FUDForum. Page generated in 0.01591 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software