Project: SWT
Bug 117125 Tree with columns shows horizontal scroll bar when it shouldn't
Reported: 2005-11-18 13:55:24 | Status: resolved fixed

SWT-win32, v3214 The testcase below contains a tree with a single column. When the parent shell is resized, the width of the column is set to exactly fill the available space. It works, but a horizontal scroll bar will appear even though none is needed. For some reason the widget thinks that there is one additional pixel to the right. If you replace the tree with a table (and the tree column with a table column), you don't get a horizontal scroll bar. Note: To keep the snippet simple, it does not contain code for the case where a vertical scroll bar is visible. --- import org.eclipse.swt.*; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.widgets.*; public class TreeColumnTest { public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); final Tree tree = new Tree(shell, SWT.NONE); tree.setHeaderVisible(true); final TreeColumn column = new TreeColumn(tree, SWT.LEFT); shell.addControlListener(new ControlAdapter() { public void controlResized(ControlEvent e) { Rectangle area = shell.getClientArea(); int width = area.width - 2 * tree.getBorderWidth(); if (width < column.getWidth()) { column.setWidth(width); tree.setSize(area.width, area.height); } else { tree.setSize(area.width, area.height); column.setWidth(width); } } }); shell.setSize(300, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } }

Files changed in fix:
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java