简体   繁体   中英

Java SWT control modified doesn't change

I'm making a couple of programs for a chat: a server and the client.

Both of them have a GUI made with SWT. Server always runs great.

In the other side, the GUI of the client doesn't. When I connect to the server, the client ask about the connected clients, and the server answer with X messages, one with each name. I've checked the server really send the names and the client receives them.

But, even when I've received the messages, sometimes the GUI shows them, and other times it doesn't. Even in the same execution, some names can be put into the GUI and others can not.

I think It could be a problem of SWT, especially about the method to modify the GUI.

As You would have supposed, I'm working with threads, even to modify the GUI. Because I want to modify GUI from a thread, I've to use the method "Display.asyncExec", so every time I do a change on GUI I do something like this:

OurDisplay.asyncExec( new Runnable() {

    public void run()
    {

        MyText.append("#The user " + OurName + " has asked us about other clients\n");

    }

});

I don't know where can be the problem, because the Server uses the same but It runs fine.

Maybe I would notice, that in the main (both of them, server and client) program I'm using this other code in order to not finish the program execution before I close the window (Shell) i'm working with:

while (!ServerShell.isDisposed())
{
    if (!ourDisplay.readAndDispatch())
        ourDisplay.sleep();
}

Any idea?

Thanks

- EDIT - Answer to Comment nº1 - (I can't answer with a comment, i don't know why)

I didn't. I've tried with "syncExec" method in order to have my thread waiting the modification of the GUI. However this neither does work.

I don't know how to see the Display queue, I'm looking for it. Thanks for the idea.

And I will try to catch the exceptions that the Runnable can be throwing. I will report news.

Make up some try/catch, you will see a typical problem: trying to update a GUI while it is buisy. The exception is surpressed until you let it rip.

I assume you've got a Eclipse RCP Application there - right? The please use the Eclipse Job processing for updating the GUI (UIJob). That works thousand times better than those asyncExec(Runnable) calls, cause the Eclipse Framework will figure the timing with the GUI updates.

http://www.vogella.com/articles/EclipseJobs/article.html

Lars Vogel has a great Tutorial on the Job processing thingy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM