質問

I have a panel with multiple JTextFields. One field holds a coordinate value and when it gains focus it becomes set as an active text field singleton. This is done so that when the field loses focus due to the user clicking on the map, the field is still updated with coordinates.

I want to make the field stop updating with coordinates once focus has changed to another text field.

Right now, the only way I can achieve this is by disabling the active text field singleton when any other text field gains focus. This doesn't seem too elegant to me since I will have to add a focus listener to every new text field and then disable the active text field singleton.

役に立ちましたか?

解決 2

I was able to come up with a solution using the "getOppositeComponent" method on the FocusEvent. This lets me check the instance of the opposite component. If it is the map, I can keep the active text field singleton, if it is anything else, then I can remove it.

他のヒント

With FocusGained and FocusLost you can just do: if (FocusLost from JTextfield) stop updating

(FYI: this is not actual code)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top