Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 179279

Summary: Tree with PaintItem listener only shows horizontal scrollbar if MeasureItem is hooked
Product: [Eclipse Project] Platform Reporter: Markus Keller <markus.kell.r>
Component: SWTAssignee: Steve Northover <snorthov>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: pali
Version: 3.3   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 177339    

Description Markus Keller CLA 2007-03-26 07:00:26 EDT
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 ();
}
}
Comment 1 Steve Northover CLA 2007-05-12 08:40:55 EDT
This is a duplicate that has been fixed for a week or so (can't find the number).  If not fixed, please reopen.