JDeveloper, thread and user interaction

Hello,

I'm developing a JDeveloper Swing application that receives data from a scale to be printed on the screen (this is done in a thread). At the same time, the user can interact with the screen and update fields. Sometimes I experience that my application blocks, and I have to restart. I believe that this is because the screen is updated by the two threads (scale and user) at the same time (?).. Does anyone know how to avoid this?

/Jakob

[465 byte] By [jakob_ma] at [2007-11-26 19:02:21]
# 1
Are the threads using SwingUtilties invokeLater method to update the GUI?
zadoka at 2007-7-9 20:48:09 > top of Java-index,Desktop,Core GUI APIs...
# 2
no
jakob_ma at 2007-7-9 20:48:09 > top of Java-index,Desktop,Core GUI APIs...
# 3
> noUpdates to the GUI need to be done on the event dispatching thread. http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html
zadoka at 2007-7-9 20:48:09 > top of Java-index,Desktop,Core GUI APIs...
# 4

Ok, thank you..

I now use a Swing timer to call the actionPerformed(..) methode.

In this methode I update a text field on the screen, whenever the weight is changing.

What about "normal" user updates to GUI, i.e. combobox dropdowns, field updates etc ? Do I have to handle these events in the same actionPerformed(..) methode as the timer thread is calling, or may I define an actionListener for each component containing its own actionPerformed(..) methode ?

If I have to use the same actionPerformed(..) for all GUI updates, should this methode be defined synchronized, like

public synchronized void actionPerformed(ActionEvent e) ?

Regards Jakob

jakob_ma at 2007-7-9 20:48:09 > top of Java-index,Desktop,Core GUI APIs...
# 5
Use separate listeners.
itchyscratchya at 2007-7-9 20:48:09 > top of Java-index,Desktop,Core GUI APIs...