Skip to main content



      Home
Home » Eclipse Projects » JFace » Resize tree on collapsing and expanding
Resize tree on collapsing and expanding [message #1748340] Tue, 22 November 2016 06:04 Go to next message
Eclipse UserFriend
Hi,

I like to resize the tree when the tree collapses and expands so that it only takes up the space that it needs. For this I am using this piece of code:

	tree.addTreeListener(new TreeListener()
	{
		@Override
		public void treeExpanded(TreeEvent e)
		{
			tree.getParent().pack();
		}

		@Override
		public void treeCollapsed(TreeEvent e)
		{
			tree.getParent().pack();
		}
	});


However, the events are to early to call pack on the parent and no resize is done. When calling pack just a little bit later works perfectly. Is there anybody that does know how to solve this?

Thanks, Michiel

[Updated on: Tue, 22 November 2016 06:24] by Moderator

Re: Resize tree on collapsing and expanding [message #1748421 is a reply to message #1748340] Tue, 22 November 2016 19:47 Go to previous messageGo to next message
Eclipse UserFriend
You can use asyncExec() to submit a task to run in the UI event queue:
tree.getDisplay().asyncExec(new Runnable() {
   public void run() {
      tree.getParent().pack();
   }});

That's usually sufficient.
Re: Resize tree on collapsing and expanding [message #1748451 is a reply to message #1748421] Wed, 23 November 2016 04:46 Go to previous message
Eclipse UserFriend
Thanks Brian! This solves the issue.
Previous Topic:Slow reaction of Eclipse Editors on a Windows VM
Next Topic:TableViewer hiding columns in MAC
Goto Forum:
  


Current Time: Thu Jul 17 00:07:09 EDT 2025

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

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

Back to the top