Bug 88441 - [Tree] Shows unnecessary horizontal scrollbar after setFont()
Summary: [Tree] Shows unnecessary horizontal scrollbar after setFont()
Status: RESOLVED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Steve Northover CLA
QA Contact:
URL:
Whiteboard:
Keywords: ui
Depends on:
Blocks:
 
Reported: 2005-03-18 07:22 EST by Benjamin Pasero CLA
Modified: 2005-04-07 13:49 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Pasero CLA 2005-03-18 07:22:45 EST
Setting the Font of a TreeItem to Bold styl makes it require more horizontal
width. This results in a horizontal scrollbar in case the available width is not
enough. However, when resetting the TreeItem back to normal Font, the Scrollbar
is still showing, even if not required.


Steps to reproduce:
- After start, resize the Sash to the left so that a horizontal Scrollbar is
showing. 

- Now press the Button, the font of the TreeItem is changing to Bold. Notice
that the horizontal Scrollbar is growing a bit (as expected). 

- Now press the button again, the font of the TreeItem changes back to normal,
but the Scrollbar is now becoming smaller.

Expected results: The scrollbar sizes back to its original size that it had
after start.

Snippet:

public class Main {
  static boolean showsBold = false;

  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    final Font boldFont = new Font(display, "Helvetica", 20, SWT.BOLD);
    final Font normalFont = new Font(display, "Helvetica", 20, SWT.NORMAL);

    SashForm form = new SashForm(shell, SWT.HORIZONTAL | SWT.SMOOTH);
    form.setLayout(new FillLayout());

    final Composite child1 = new Composite(form, SWT.NONE);
    child1.setLayout(new GridLayout(1, false));

    Composite child2 = new Composite(form, SWT.NONE);
    child2.setLayout(new FillLayout());

    final Tree tree = new Tree(child1, SWT.BORDER);
    tree.setFont(normalFont);
    tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    final TreeItem item = new TreeItem(tree, SWT.NONE);
    item.setText("Hello World Hello World");
    item.setFont(normalFont);

    Button b = new Button(child2, SWT.PUSH);
    b.setText("push me");
    b.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e) {
        if (!showsBold)
          item.setFont(boldFont);
        else
          item.setFont(normalFont);

        showsBold = !showsBold;
      }
    });

    form.setWeights(new int[] { 50, 50 });

    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
  }
}
Comment 1 Benjamin Pasero CLA 2005-03-18 07:24:57 EST
Typo:

"- Now press the button again, the font of the TreeItem changes back to normal,
but the Scrollbar is now becoming smaller."

is meant to be

"- Now press the button again, the font of the TreeItem changes back to normal,
but the Scrollbar is _NOT_ becoming smaller."
Comment 2 John Smith CLA 2005-03-21 18:16:57 EST
I'm working on an in-place editor and I also see this problem. I noticed that
the Navigator view also has an in-place editor and does not have this problem,
but I haven't figured out what the difference is. Calls to pack() and
layout(true) don't have any effect though.
Comment 3 Benjamin Pasero CLA 2005-03-22 04:14:38 EST
Yes, the "in place" Editor of the Navigator is definitly something different to
what is described in the Snippets section or the TreeEditor's JavaDoc. I already
posted to the newsgroup asking for how Eclipse is doing it but did not yet
received an answer. 

The main differences I noticed is:

1.) The black-box (edit textfield) has a bigger width in Eclipse's Navigator

2.) The text of the TreeItem that is being edited is not moving to the left. In
the Snippet I am seeing a slight movement (~1px) to the left as soon as the
editing begins.

Ben
Comment 4 Steve Northover CLA 2005-04-07 13:47:37 EDT
This is Windows platform behavior.  It looks like Windows never makes the 
scroll bar smaller.  I changed your code to set a new smaller string ("a") and 
never set the font.  The scroll bar stayed.
Comment 5 Steve Northover CLA 2005-04-07 13:49:05 EDT
Please open another bug report describing what you are seeing in the in-place 
editor if you want to persue that matter.  Thanks.