Atitit. swt & #160; the thread calls the ui control method, atitit. swtui

Source: Internet
Author: User

Atitit. swt thread calls the ui control method, atitit. swtui

Atitit. swt thread call the ui control method

 

 

1 SwingUtilities. invokeLater1

2 display. asyncExec method 1

3 display. timerExec (500, timer); 2

4. But sometimes it is not necessary to perform regular detection when the program is executed, and sometimes external things are required to stimulate this. There are 2nd solutions, and a built-in class is written, it can be placed in the event listening method and then stimulated: 2

5. Reference 3

 

1 SwingUtilities. invokeLater

 

SwingUtilities. invokeLater (new Runnable () {@ Override public void run () {label2.setText (x + "");}});

I have also encountered this problem. There is an updateUI () method that can be solved.

 

2 Display. asyncExec Method

Using the display. asyncExec method provided by SWT, it is found that the essence is not to open another Thread, but to call the run method once, so the program will die when Thread. sleep is called.

Sometimes another thread

 

 

Author: old wow's paw Attilax iron, EMAIL: 1466519819@qq.com

Reprinted please indicate Source: http://www.cnblogs.com/attilax/

 

3 Display. timerExec (500, timer );

1. Final Runnable timer = new Runnable (){

2. Int count = 0;

3. Public void run (){

4. Synchronized (this ){

5. Try {

6. Text. setText (

7. Integer. toString (count ++ ));

8. } Catch (Exception e ){

9. E. printStackTrace ();

10. }

11. }

12. }

13. };

14. While (shell! = Null &&! Shell. isDisposed ()){

15.

16. If (! Display. readAndDispatch ())

17. Display. sleep ();

18. Else

19. Display. timerExec (500, timer );

 

 

4 But sometimes the program does not have to be periodically detected during execution, and sometimes external things are required to stimulate the emergence of 2nd solutions. Write a built-in class that can be placed in the event listening method, then inspire:

1. New Thread (){

2. Private Runnable cmd = new Runnable (){

3. Public void run (){

4. Shell. setText (String. valueOf (counter ++ ));

5. }

6. };

7. Public void run (){

8. While (true ){

9. Try {

10. Thread. sleep (2000 );

11. } Catch (InterruptedException e ){

12. Return;

13. }

14. Display. asyncExec (cmd );

15. }

16. }

17. }

18. . Start ();

 

 

5 Reference

A special implementation method of timer in SWT _ display. asyncExec_display.syncExec... solution to program death and no response when threads in SWT exchange visit-fm2005 column-blog channel-CSDN.NET.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.