|
Re: Auto-sized TreeViewer columns [message #481900 is a reply to message #479616] |
Mon, 24 August 2009 16:40 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
Hi Marian, sorry for the late reply,
The Expand callback is sent when an item is expanding, but has not yet
completed. So I think the only way to do what you want is to listen for
SWT.Expand and asyncExec() the pack() of the column so that the expansion
completes first, as shown below:
public static void main (String [] args) {
final Display display = new Display ();
final Shell shell = new Shell (display);
shell.setBounds(10,10,250,250);
final Tree tree = new Tree(shell, SWT.NONE);
tree.setBounds(10,10,200,200);
tree.setHeaderVisible(true);
final TreeColumn column = new TreeColumn(tree, SWT.NONE);
TreeItem item = new TreeItem(tree, SWT.NONE);
item.setText("root");
for (int i = 0; i < 5; i++) {
item = new TreeItem(item, SWT.NONE);
item.setText("descendent " + i);
}
tree.addListener(SWT.Expand, new Listener() {
public void handleEvent(Event event) {
display.asyncExec(new Runnable() {
public void run() {
if (tree.isDisposed()) return;
column.pack();
}
});
}
});
column.pack();
shell.open();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
HTH,
Grant
"Marian Schedenig" <marian.schedenig@qualysoft.com> wrote in message
news:h5s9br$9av$1@build.eclipse.org...
> Hi!
>
> In a Windows Explorer type application, I have a tree next to a table.
> To make the elements in the tree line up vertically with the elements in
> the table, I want to have a single column in the tree and display a
> header for it.
>
> The problem is that the column will not resize correctly. When expanding
> new levels, I have to manually call pack() on the column, but with all
> the listeners I've tried, I can only make this happen:
>
> 1) Before the new elements revealed by an expand event are displayed
> 2) When the tree selection has changed
>
> Meaning that expanding a new level will show cut off elements until I
> either expand another item or change the selection in the tree.
>
> What can I do to make the column width adapt automatically to the
> longest label in the tree? Ideally, I would also have the column's
> minimum width be the exact width of the tree widget, so that I don't
> actually see an (unnecessary) column separator when the tree isn't
> filled horizontally.
>
> Thanks,
> Marian.
|
|
|
|
Powered by
FUDForum. Page generated in 0.02981 seconds