Hi guys,
First, thanks for your fast reply…that’'s cool!
Here’‘s an example of code I’'d like to run whitout SWTerror using Smack and SWT:
package fr.elh.smack;
import java.util.Collection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
public class MainSwt {
private Shell sShell = null;
private Tree tree = null;
public XMPPConnection conn = null; // @jve:decl-index=0:
public Roster roster = null;
/**
*/
public static void main(String[] args) {
Display display = Display.getDefault();
MainSwt thisClass = new MainSwt();
thisClass.createSShell();
thisClass.sShell.open();
while (!thisClass.sShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
/**
- This method initializes sShell
*/
private void createSShell() {
sShell = new Shell();
sShell.setText(“Shell”);
sShell.setSize(new Point(300, 200));
sShell.setLayout(new FillLayout());
tree = new Tree(sShell, SWT.NONE);
try {
conn = new XMPPConnection(“myJabberDomain”, 5222);
conn.login(“myLogin”, “myPwd”);
} catch (XMPPException e) {
e.printStackTrace();
}
roster = conn.getRoster();
roster.addRosterListener(new RosterListener(){
public void entriesAdded(Collection arg0) {}
public void entriesUpdated(Collection arg0) {}
public void entriesDeleted(Collection arg0) {}
public void presenceChanged(String arg0) {
//this line produces the SWTError : org.eclipse.swt.SWTException: Invalid thread access
System.out.println("read SWT tree from smack thread: " + tree);[/b]
}
});
}
}
Could you help me to find the right code using threads?
Thank you very much!!
e07