Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Technology Project and PMC » [SWT][Thread] Strange Exception
[SWT][Thread] Strange Exception [message #38128] Fri, 13 December 2002 18:18 Go to next message
Eclipse UserFriend
Originally posted by: yolepro.hotmail.com

Hello, I have a strange problem using Thread with SWT Display.
The error message that i have is the following :

org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:2119)
at org.eclipse.swt.SWT.error(SWT.java:2051)
at org.eclipse.swt.widgets.Widget.error(Widget.java:370)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:301)
at org.eclipse.swt.custom.StyledText.setText(StyledText.java:69 99)
at TestSWT.errPrint(TestSWT.java:56)
at ChatLecteur.run(ChatLecteur.java:26)
at java.lang.Thread.run(Unknown Source)

When I use Swing with a JFrame it works correctly

My main class :

public class ClientApplication

boolean packFrame = false;

public ClientApplication()

TestSwing frameSwing = new TestSwing();
TestSWT frameSWT = new TestSWT();
frameSwing.start();
frameSWT.start();
}

public static void main(String[] args)

new ClientApplication();
}
}

Nothing complicated for the main, now is the code for main SWING interface
that work correctly :

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class TestSwing extends JFrame


JPanel contentPane;
JTextField jTFWriting = new JTextField();
JButton jBSend = new JButton();
GridLayout gridBagLayout1 = new GridLayout();

public void
rt(){
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(gridBagLayout1);
this.setSize(new Dimension(240, 50));
jBSend.addActionListener(new TestSwing_Connexion_actionAdapter(this));
contentPane.add(jTFWriting);
contentPane.add(jBSend);
this.setVisible(true);
}

public void connecter() {
try {
ChatLecteurSwing chatlecteur = new ChatLecteurSwing(this);
(new Thread(chatlecteur)).start();
} catch(Exception exception) {
errPrint("Grosse Erreur de Thread");
}
}

public void errPrint (
String msg) {jTFWriting.setText(msg);}
public void msgPrint (String msg) {jTFWriting.setText(msg);}
}

class TestSwing_Connexion_actionAdapter implements ActionListener

TestSwing adaptee;

TestSwing_Connexion_actionAdapter(TestSwing adaptee)

this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)

adaptee.connecter();
}
}

class ChatLecteurSwing implements Runnable

private TestSwing ihm;
ChatLecteurSwing(TestSwing ihm)

this.ihm = ihm;
}
public void run()

String s = "Diffusion de la mort";
try

if(s == null)

ihm.errPrint("Votre message n'est pas conforme");
return;
} else

ihm.errPrint(s);
}
}catch(Exception exception)

ihm.errPrint("ChatLecteur erreur: " + exception);
return;
}
}
}

Now the problem is for the pretty same SWT class that genere SWTException
when I click on the butt1 button. This button run a Thread that gives me a
static response :

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.layout.*;

public class TestSWT


protected StyledText butt2;

public void start ()

Display display = new Display ();
Shell shell = new Shell (display);
GridLayout gridLayout = new GridLayout();
shell.setLayout(gridLayout);
Composite c1 = new Composite(shell, SWT.BORDER);
gridLayout = new GridLayout();
gridLayout.numColumns = 3;
c1.setLayout(gridLayout);
c1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

Button butt1 = new Button(c1, SWT.PUSH);
butt2 = new StyledText (c1, SWT.SINGLE | SWT.BORDER);
butt1.addListener (SWT.Selection, new
ClientSWT_Connexion_actionAdapter(this));

GridData gridData = new GridData();
gridData.widthHint = 40;
butt1.setLayoutData(gridData);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
butt2.setLayoutData(gridData);

shell.pack ();
shell.open ();
shell.setSize(200,70);
while (!shell.isDisposed ())

if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}

public void connecter()

try

ChatLecteurSWT chatlecteur = new ChatLecteurSWT(this);
(new Thread(chatlecteur)).start();
} catch(Exception exception)

errPrint("Grosse Erreur de Thread");
}
}

public void errPrint (String msg) {butt2.setText(msg);}
public void msgPrint (String msg) {butt2.setText(msg);}
}

class ClientSWT_Connexion_actionAdapter implements Listener

TestSWT adaptee;
ClientSWT_Connexion_actionAdapter(TestSWT adaptee) {this.adaptee =
adaptee;}
public void handleEvent(Event e) {adaptee.connecter();}
}

class ChatLecteurSWT implements Runnable

private TestSWT ihm;
ChatLecteurSWT(TestSWT ihm)

this.ihm = ihm;
}
public void run()

String s = "Diffusion de la mort";
try

if(s == null)

ihm.errPrint("Votre message n'est pas conforme");
return;
} else

ihm.errPrint(s);
}
}catch(Exception exception)

ihm.errPrint("ChatLecteur erreur: " + exception);
return;
}
}
}

You can see these too classes are relatively the same. But i can't
understand why with SWT I have a Exception
I Hope I have been clear, and problably you will find quickly with i'm doing
wrong.

Thanks
Re: [SWT][Thread] Strange Exception [message #49912 is a reply to message #38128] Mon, 24 March 2003 11:24 Go to previous message
Eclipse UserFriend
Originally posted by: therier.yahoo.com

CF "Invalid thread access" Topic.


"yolepro" <yolepro@hotmail.com> a
Re: [SWT][Thread] Strange Exception [message #591883 is a reply to message #38128] Mon, 24 March 2003 11:24 Go to previous message
Eclipse UserFriend
Originally posted by: therier.yahoo.com

CF "Invalid thread access" Topic.


"yolepro" <yolepro@hotmail.com> a
Previous Topic:Eclipse source: Dependency handling
Next Topic:Importing project into workspace from external plugin
Goto Forum:
  


Current Time: Thu Apr 25 03:46:04 GMT 2024

Powered by FUDForum. Page generated in 0.04138 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top