Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » How do I get rid of unwanted scroll bars in tree viewer?(They won't go away after setting the tree item's width in OwnerDrawLabelProvider)
icon5.gif  How do I get rid of unwanted scroll bars in tree viewer? [message #655370] Sun, 20 February 2011 02:21 Go to next message
SBS  is currently offline SBS
Messages: 57
Registered: January 2011
Member
I have a tree viewer that uses an OwnerDrawLabelProvider to draw customised labels for tree items. One of the methods in this interface is the measure() method where you define the bounds of the label. Whenever I expand a node in the tree I calculate the maximum width of all visible tree items and use this to set the width in the measure() method and this works fine with the scroll bars appearing as required if there are items wider than the client area. However, when I collapse that node I want the scroll bars to disappear when there are no longer any tree items wider than the client area but this is not working.

I know that the measure() method is being called and that I am setting the label widths down to something which should not require the presence of scroll bars but it appears the viewer or the tree is "remembering" that it had wide tree items and decides to keep the scroll bars around.

How can I get these scroll bars to go away when they really are not required anymore? I have tried calling tree.layout() and tree.getParent().pack() etc. but none of these methods work. The viewer just thinks it needs to show these scroll bars anyway.
Re: How do I get rid of unwanted scroll bars in tree viewer? [message #655973 is a reply to message #655370] Wed, 23 February 2011 15:28 Go to previous message
Grant Gayed is currently offline Grant Gayed
Messages: 2151
Registered: July 2009
Senior Member
Hi,

It sounds like you're seeing
https://bugs.eclipse.org/bugs/show_bug.cgi?id=182612 .

The only workaround I can suggest trying is to create a single column in
your Tree, as the scrollbar will update itself in response to column width
shrinks. The SWT-only snippet below demonstrates this, it grows a column to
a width that requires a scrollbar, then shrinks it to make the scrollbar go
away. You won't be able to use this code as-is since you're working at the
JFace level, but it should be helpful for writing what you need.

public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(10,10,300,300);
shell.setLayout(new FillLayout());
final Tree tree = new Tree(shell, SWT.NO_SCROLL | SWT.H_SCROLL);
tree.setHeaderVisible(true);
new TreeColumn(tree, SWT.NONE);
new TreeItem(tree, SWT.NONE).setText("hi");
tree.addListener(SWT.MeasureItem, new Listener() {
public void handleEvent(Event event) {
event.width = counter;
System.out.println(counter);
}
});
display.timerExec(1000, new Runnable() {
public void run() {
if (tree.isDisposed()) return;
counter += step;
if (counter == 10) {
step = 20;
}
if (counter == 350) {
step = -20;
}
tree.getColumn(0).pack();
display.timerExec(1000, this);
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}

As a side note, I notice that this is not working on OS X in the eclipse/swt
3.7 stream, so I've logged
https://bugs.eclipse.org/bugs/show_bug.cgi?id=337984 .

Grant


"SBS" <jturnbul@uow.edu.au> wrote in message
news:ijptg6$5ou$1@news.eclipse.org...
>I have a tree viewer that uses an OwnerDrawLabelProvider to draw customised
>labels for tree items. One of the methods in this interface is the
>measure() method where you define the bounds of the label. Whenever I
>expand a node in the tree I calculate the maximum width of all visible tree
>items and use this to set the width in the measure() method and this works
>fine with the scroll bars appearing as required if there are items wider
>than the client area. However, when I collapse that node I want the scroll
>bars to disappear when there are no longer any tree items wider than the
>client area but this is not working.
>
> I know that the measure() method is being called and that I am setting the
> label widths down to something which should not require the presence of
> scroll bars but it appears the viewer or the tree is "remembering" that it
> had wide tree items and decides to keep the scroll bars around.
>
> How can I get these scroll bars to go away when they really are not
> required anymore? I have tried calling tree.layout() and
> tree.getParent().pack() etc. but none of these methods work. The viewer
> just thinks it needs to show these scroll bars anyway.
Previous Topic:Background Image Adjustment in TreeViewer/Control
Next Topic:how to sort alphanumeric values in org.eclipse.jface.viewers.ViewerSorter
Goto Forum:
  


Current Time: Wed Sep 17 17:44:54 GMT 2014

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

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