views:

98

answers:

3

hi,

i've panel which contains a text field for entering number and a submit button sometimes new (updated) value can not be sent when i click the button (the previous value of the field is sent)

in the debug mode, i see that sometimes

AbstractButton.fireActionPerformed()

is called (which gets the value of the field at that time and then submits) by event dispatch thread before

JFormattedTextFiled.FocusLostHandler

and

JFormattedTextField.commitEdit()

(which updates the value of the field).

i think jbutton event should have never been called before the text field loses the focus and updates its value

any idea about the problem?

i'm using xp-sp2 and java 1.6.0_06-b02

A: 

Sorry, I have re-read your question - I have misunderstood it previously.

I cannot tell you why the focus is not moved from the field, but we had a similar issue in our application, but with the JTable and edits were not committed to the CellRender despite that we have set all required table properties. We just had to move focus away from the table cell as the first action in our event listener

ZloiAdun
A: 

thanks for replies guys and excuse me starting the same therad in java forum (i was not aware of the rules): http://forums.sun.com/thread.jspa?threadID=5445465&tstart=0

anyway, actually i'm interested in the cause of the problem rather than the solution there are two cases in the EventQueue

here are the events for case 1:

MouseEvent (MOUSE_RELEASED)
MouseEvent (MOUSE_CLICKED)
InvocationEvent
InvocationEvent
InvocationEvent
CausedFocusEvent (FOCUS_LOST; opposite: JButton; source: FormattedNumberField)
CausedFocusEvent (FOCUS_GAINED; opposite: FormattedNumberField; source: JButton)
InvocationEvent
MouseEvent (MOUSE_MOVED)
MouseEvent (MOUSE_EXITED)

and here are the events for case 2:

CausedFocusEvent (FOCUS_LOST; opposite: JButton; source: FormattedNumberField)
CausedFocusEvent (FOCUS_GAINED; opposite: FormattedNumberField; source: JButton)
InvocationEvent
InvocationEvent
...
MouseEvent (MOUSE_RELEASED)
MouseEvent (MOUSE_CLICKED)
InvocationEvent
InvocationEvent
...
MouseEvent (MOUSE_MOVED)
MouseEvent (MOUSE_EXITED)

maybe java does not guarantee the order of the events. if it's true it would be a common problem but it's an unusual and very rare situation. even i can't reproduce this problem in other gui panels. i wonder what may cause this problem.

karahanozturk
A: 

I'm pretty sure the the EventQueue keeps things sequential, but I've seen the debugger change the apparent order when I forget to use invokeLater() from another thread.

Catalina Island