Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Resize tree on collapsing and expanding
Resize tree on collapsing and expanding [message #1748340] Tue, 22 November 2016 11:04 Go to next message
Michiel Werk is currently offline Michiel WerkFriend
Messages: 3
Registered: July 2009
Junior Member
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 11:24]

Report message to a moderator

Re: Resize tree on collapsing and expanding [message #1748421 is a reply to message #1748340] Wed, 23 November 2016 00: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 09:46 Go to previous message
Michiel Werk is currently offline Michiel WerkFriend
Messages: 3
Registered: July 2009
Junior Member
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: Sat Apr 20 03:59:50 GMT 2024

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

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

Back to the top