Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Auto-sized TreeViewer columns
Auto-sized TreeViewer columns [message #479616] Tue, 11 August 2009 17:22 Go to next message
Marian Schedenig is currently offline Marian SchedenigFriend
Messages: 25
Registered: July 2009
Junior Member
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.
Re: Auto-sized TreeViewer columns [message #481900 is a reply to message #479616] Mon, 24 August 2009 16:40 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
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.
Re: Auto-sized TreeViewer columns [message #482455 is a reply to message #481900] Wed, 26 August 2009 15:33 Go to previous message
Marian Schedenig is currently offline Marian SchedenigFriend
Messages: 25
Registered: July 2009
Junior Member
Grant Gayed wrote:
> 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:

Excellent, this does nearly exactly what I need. What it doesn't do is
handle expansions triggered by my code/the TreeView. But I can just
re-pack the column manually in this case.

Cheers,
Marian.
Previous Topic:SWT.SetData in virtual table not working when SWT.MeasureItem is added
Next Topic:How to show horizontal scrollbar in table without using TableColumn.pack()
Goto Forum:
  


Current Time: Fri Aug 23 13:04:33 GMT 2019

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

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

Back to the top