Bug 153398 Invalid thread access in Snippet133
Running SWT Snippet 133 (print text to printer) throws this exception: Exception in thread "Printing" org.eclipse.swt.SWTException: Invalid thread access at org.eclipse.swt.SWT.error(SWT.java:3374) at org.eclipse.swt.SWT.error(SWT.java:3297) at org.eclipse.swt.SWT.error(SWT.java:3268) at org.eclipse.swt.widgets.Widget.error(Widget.java:435) at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:331) at org.eclipse.swt.widgets.Control.getFont(Control.java:939) at org.eclipse.swt.snippets.Snippet133.print(Snippet133.java:230) at org.eclipse.swt.snippets.Snippet133$7.run(Snippet133.java:204) It works if you patch the line: printingThread.start(); with this: display.syncExec(printingThread);
examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet133.java
Font printerFont;
	Color printerForegroundColor, printerBackgroundColor;
	int lineHeight = 0;
	int tabWidth = 0;
	int leftMargin, rightMargin, topMargin, bottomMargin;
	int x, y;
	int index, end;
	String textToPrint;
	String tabs;
	StringBuffer wordBuffer;
	public static void main(String[] args) {
		new Snippet133().open();
	}
	
	void open() {
		display = new Display();
		shell = new Shell(display);
		shell.setLayout(new FillLayout());
		shell.setText("Print Text");
		text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
		
		Menu menuBar = new Menu(shell, SWT.BAR);
		shell.setMenuBar(menuBar);
		MenuItem item = new MenuItem(menuBar, SWT.CASCADE);
		item.setText("&File");
		Menu fileMenu = new Menu(shell, SWT.DROP_DOWN);
		item.setMenu(fileMenu);
		item = new MenuItem(fileMenu, SWT.PUSH);
		item.setText("&Open...");
		item.setAccelerator(SWT.CTRL + 'O');