Community
Participate
Working Groups
I20070323-1616 A Tree with a PaintItem listener only shows a horizontal scrollbar if MeasureItem is also hooked: public class SnippetNoHScrollbar { public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout (new FillLayout()); final Tree tree= new Tree(shell, SWT.MULTI); for (int i= 0; i < 21; i++) { TreeItem item= new TreeItem(tree, SWT.NONE); item.setText("Item with long name" + i); for (int j= 0; j < 11; j++) { TreeItem subItem= new TreeItem(item, SWT.NONE); subItem.setText("SubItem " + j); } } final Color red= display.getSystemColor(SWT.COLOR_RED); tree.addListener(SWT.PaintItem, new Listener() { public void handleEvent(Event e) { e.gc.setForeground(red); e.gc.drawRectangle(e.x + 1, e.y + 1, e.width - 3, e.height - 3); } }); // tree.addListener(SWT.MeasureItem, new Listener() { // public void handleEvent(Event e) { // // uncomment to make horizontal scrollbar appear ... // } // }); shell.setSize(50, 300); shell.open(); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); } }
This is a duplicate that has been fixed for a week or so (can't find the number). If not fixed, please reopen.