Java中事件的顺序 [英] Sequence of the Events in Java

查看:130
本文介绍了Java中事件的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个独立组件的事件,但是有一个问题。 JTabbedPane的stateChanged事件在JFormattedField的focusLost事件之前被触发。有没有办法在focusLost事件之后触发stateChange事件。

I have two events for two seperate components, but there is a problem. JTabbedPane's stateChanged event is fired before JFormattedField's focusLost event. Is there a way of making stateChange event to be fired after focusLost event.

谢谢,
金枪鱼

Thanks, Tuna

推荐答案

事件将被触发,订单不能保证,并可能在各种平台上有所不同。

While Java guarantees event will be fired the order is not guaranteed and may differ on various platforms.

潜在的解决方案是将StateChanged代码包装在SwingUtilities.invokeLater()中。这将把代码放在事件调度线程(EDT)的末尾,所以它应该在focusLost代码之后执行。

A potential solution is to wrap the stateChanged code in a SwingUtilities.invokeLater(). This will place the code at the end of the Event Dispatch Thread (EDT) so it should execute after the focusLost code.

这篇关于Java中事件的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆