Project: SWT
Bug 131625 Tree adds useless vertical scrollbar
Reported: 2006-03-13 19:43:02 | Status: resolved fixed

SWT CVS win32 The tree adds a vertical scrollbar that is useless, the table does not. I'm also not sure why the clientArea() of the tree is negative(0,-20...). TREE CLIENT AREA: Rectangle {0, -20, 392, 562} BOUNDS: Rectangle {0, 0, 396, 566} TABLE CLIENT AREA: Rectangle {0, 0, 392, 562} BOUNDS: Rectangle {396, 0, 396, 566} public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final int columns = 5; final int itemCount = 15; final Tree tree = new Tree(shell, SWT.BORDER | SWT.VIRTUAL | SWT.FULL_SELECTION | SWT.MULTI); tree.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); for (int i = 0; i < columns; i++) new TreeColumn(tree, SWT.LEFT).setWidth(75); tree.setHeaderVisible(true); tree.setLinesVisible(true); tree.setSortDirection(SWT.DOWN); tree.setSortColumn(tree.getColumn(0)); tree.addListener(SWT.SetData, new Listener() { public void handleEvent(Event event) { TreeItem item = (TreeItem) event.item; int index = event.index; TreeItem parentItem = item.getParentItem(); String text = null; if (parentItem == null) { text = "node " + tree.indexOf(item); } else { text = parentItem.getText() + " - " + parentItem.indexOf(item); } for (int i = 0; i < columns; i++) { item.setText(i, text); } if (index % 2 == 0) { Color c = display.getSystemColor(SWT.COLOR_DARK_YELLOW); item.setBackground(c); } item.setItemCount(itemCount); } }); final Table table = new Table(shell, SWT.VIRTUAL | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); table.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); for (int i = 0; i < columns; i++) new TableColumn(table, SWT.LEFT).setWidth(75); table.setLinesVisible(true); table.setHeaderVisible(true); table.setSortDirection(SWT.DOWN); table.setSortColumn(table.getColumn(0)); table.addListener(SWT.SetData, new Listener() { public void handleEvent(Event event) { TableItem item = (TableItem) event.item; int index = event.index; String text = null; text = "node " + index; for (int i = 0; i < columns; i++) { item.setText(i, text); } if (index % 2 == 0) { Color c = display.getSystemColor(SWT.COLOR_DARK_YELLOW); item.setBackground(c); } } }); final int timerDelay = 1250; final Runnable r = new Runnable() { public void run() { if (c++ >= columns - 1) c = 0; int dir = table.getSortDirection() == SWT.DOWN ? SWT.UP : SWT.DOWN; tree.setItemCount(itemCount); table.setItemCount(itemCount); table.setSortDirection(dir); table.setSortColumn(table.getColumn(c)); tree.setSortColumn(tree.getColumn(c)); tree.setSortDirection(dir); display.timerExec(timerDelay, this); } }; display.timerExec(timerDelay, r); shell.setSize(800, 600); shell.open(); System.err.println("TREE CLIENT AREA: " + tree.getClientArea() + "\tBOUNDS: " + tree.getBounds()); System.err.println("TABLE CLIENT AREA: " + table.getClientArea() + "\tBOUNDS: " + table.getBounds()); 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