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
/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.snippets;
  
/*
 * Printing example snippet: print text to printer, with word wrap and pagination
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 */
import java.io.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.printing.*;
public class Snippet133 {