Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to change text when program is running?
How to change text when program is running? [message #464308] Mon, 21 November 2005 10:19 Go to next message
Robin is currently offline RobinFriend
Messages: 7
Registered: July 2009
Junior Member
For example, I want to change text "11111111111111" to "22222222222" after
the shell is shown. I run "test.getText().setText("22222222222")" after
test.creatShell(), but it does not work because the program is in the
while loop and test.getText().setText("22222222222") will never run till
the display disposed. So anyone have idea how to do it? Below is the code.



import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class Test {


public Text text;

public void creatShell(){
Display display = Display.getDefault();
Shell shell = new Shell(SWT.MIN);

text=new Text(shell,SWT.MULTI|SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
text.setBounds(50,40,300,200);
text.setText("11111111111111");
shell.pack();

shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}

display.dispose();

}

public static void main(String[] args){

Test test=new Test();
test.creatShell();
test.getText().setText("22222222222");

}

public Text getText(){
return this.text;
}

}
Re: How to change text when program is running? [message #464315 is a reply to message #464308] Mon, 21 November 2005 14:00 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Add a button as well, and put your code in a SelectionListener on the
button.

later,
PW


Re: How to change text when program is running? [message #464317 is a reply to message #464315] Mon, 21 November 2005 14:47 Go to previous messageGo to next message
Robin is currently offline RobinFriend
Messages: 7
Registered: July 2009
Junior Member
But I dont want to add a button. I want other classes can change text
after the shell is shown.
thanks,

robin
Re: How to change text when program is running? [message #464318 is a reply to message #464317] Mon, 21 November 2005 14:56 Go to previous messageGo to next message
Stefan Langer is currently offline Stefan LangerFriend
Messages: 236
Registered: July 2009
Senior Member
You have to run the code that sets the text from a different thread than
the ui thread or who ever changes the text has to be part of the ui
thread and does this during handling a ui event message.
Beware that when you update the eventthread from a different thread use
synExec or asynExec from Display.

Regards
Stefan

Robin wrote:
> But I dont want to add a button. I want other classes can change text
> after the shell is shown.
> thanks,
>
> robin
>
Re: How to change text when program is running? [message #464360 is a reply to message #464318] Tue, 22 November 2005 03:48 Go to previous message
Robin is currently offline RobinFriend
Messages: 7
Registered: July 2009
Junior Member
hi Stefan,

Thanks for your explaination.
I think you meaning is to start "another" thread in UI thread to do some
action. But this "another" thread must be put into a event handler code in
the UI thread.

But I think I also need something( a button or something else) to trigger
the "another" thread ??

regards,

Robin
Previous Topic:SWT : Button & Image
Next Topic:Setting Text and Icon on the Wizard
Goto Forum:
  


Current Time: Fri Aug 23 15:11:53 GMT 2019

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

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

Back to the top