当浏览器/选项卡获得焦点时将焦点恢复到 Java Applet [英] Restore focus to Java Applet when Browser/Tab gains focus

查看:28
本文介绍了当浏览器/选项卡获得焦点时将焦点恢复到 Java Applet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在浏览器选项卡中运行了一个小程序.当我在同一个浏览器中切换到不同的选项卡,或 ALT-TAB 完全切换到另一个应用程序时,小程序会失去焦点.当我返回浏览器选项卡时,小程序不再获得焦点.有什么好的方法可以做到这一点吗?

I have an applet running in a browser tab. When I switch to a different tab in the same browser, or ALT-TAB to another application entirely, the applet loses focus. When I return to the browser tab, the applet doesn't gain focus again. Is there a nice way to make this happen?

我认为这是需要的 JavaScript 更改,而不是小程序本身?也许是一些 onFocus 处理程序?如果相关,我们的小程序是使用 HTML 标签创建的.

I assume it's a JavaScript change that's needed, not in the applet itself? Some onFocus handler perhaps? If it's relevant, our applet is created using an HTML <applet> tag.

推荐答案

我相信 java 有 requestFocus() 方法.它在 Component 类中,因此您的 JPanel 或您使用的任何东西都可以使用它.

I believe java has the requestFocus() method. It's in the Component class, so your JPanel or whatever you are using may be able to use this.

对于 javascript 部分,这是一个快速的谷歌搜索显示:http://www.raditha.com/java/javascript.php.希望能帮到你!

For the javascript part, this is what a quick googling reveals: http://www.raditha.com/java/javascript.php. I hope it helps you!

这篇关于当浏览器/选项卡获得焦点时将焦点恢复到 Java Applet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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