如果您想了解JMenu在Windows7LAFJava7中使用focuslost事件和java中jmenuitem的知识,那么本篇文章将是您的不二之选。我们将深入剖析JMenu在Windows7LAF
如果您想了解JMenu在Windows7 LAF Java7中使用focuslost事件和java中jmenuitem的知识,那么本篇文章将是您的不二之选。我们将深入剖析JMenu在Windows7 LAF Java7中使用focuslost事件的各个方面,并为您解答java中jmenuitem的疑在这篇文章中,我们将为您介绍JMenu在Windows7 LAF Java7中使用focuslost事件的相关知识,同时也会详细的解释java中jmenuitem的运用方法,并给出实际的案例分析,希望能帮助到您!
本文目录一览:- JMenu在Windows7 LAF Java7中使用focuslost事件(java中jmenuitem)
- c# – 如何在Windows商店(WinRT)应用程序中启用DocumentsLibrary功能?
- document.hasFocus() & $(window).blur()
- java – Window,Document vs. $wnd,$doc
- java – 如何在windows7中以管理员身份进行复制
JMenu在Windows7 LAF Java7中使用focuslost事件(java中jmenuitem)
如果在单击另一个组件时弹出菜单仍处于打开状态,则该组件不会获取该事件,因为该事件可能已被弹出窗口占用。通常,所有JPopupmenus都会发生这种情况。仅在具有Windows
LAF(Windows7)的Java 7中会发生这种情况。有解决方法吗?它是已知的错误吗?
import javax.swing.*;import java.awt.event.*;public class Test{ public static void main(String[] s) throws Exception { String lookAnfFeelClassName = UIManager.getSystemLookAndFeelClassName(); UIManager.setLookAndFeel(lookAnfFeelClassName); JMenu menu = new JMenu("TEST Menu"); JMenuItem menuItem = new JMenuItem("Menu Item 1"); JMenuBar menuBar = new JMenuBar(); menu.add(menuItem); menuBar.add(menu); final JButton b = new JButton("Test"); b.setBounds(5, 50, 60, 20); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //If the Menu is open when I press the button, the putton is not pressed //so I have to press it again. JOptionPane.showMessageDialog(b, "Button Pressed"); } } ); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(150, 150); frame.setJMenuBar(menuBar); frame.getContentPane().setLayout(null); frame.getContentPane().add(b); frame.setVisible(true); }}
答案1
小编典典这是解决该问题的魔术路线:
UIManager.put("PopupMenu.consumeEventOnClose", Boolean.FALSE);
在查看BasicPopupMenuUI类的源代码后,我发现了这一点。显然,根据代码中的以下注释,此行为是有意的设计选择,但对我来说确实感觉像是个错误。
// Ask UIManager about should we consume event that closes // popup. This made to match native apps behaviour.
顺便说一下,它也发生在Java 5和6中。
c# – 如何在Windows商店(WinRT)应用程序中启用DocumentsLibrary功能?
// DEBUG ONLY: StorageFile file = await KNownFolders.DocumentsLibrary.CreateFileAsync("hey lol.txt");
但它抛出了这个异常(我预期):
WinRT information: Access to the specified location (DocumentsLibrary) requires a capability to be declared in the manifest.
哪个好.我期待它.所以我转到Package.appxmanifest并转到Capabilities选项卡,令我惊讶的是,没有列出“DocumentsLibrary”功能.
如果它不存在,我该如何启用它?
解决方法
[Although] this capability is gone just from the UI,you still can open appxmanifest source and manually add the capability. The result will probably be the same as before – failure of certification for individual developers,so you better stay away from this trick. Microsoft strongly recommend against using Documents Library capability,suggesting Folder and File Pickers instead.
document.hasFocus() & $(window).blur()
- $(window).blur()
jquery方法:
1.当内嵌iframe时,会触发
2.当弹出上传框时,会触发
3.当出现弹出“是否允许麦克风或摄像头”时,会触发
- document.hasFocus():用于检测文档(或文档内的任一元素)是否获取焦点
1.当内嵌iframe时,不触发
2.当弹出上传框时,会触发
3.当出现弹出“是否允许麦克风或摄像头”时,会触发
方法 | chrome | ie | firefox | safari | opare |
---|---|---|---|---|---|
hasFocus() | 30.0 | 6.0 | 3.0 | Yes | 23.0 |
- document.activeElement:当前文档获取焦点的元素js对象
诡异问题:document.activeElement 为 HTMLBodyElement; 但 document.hasFocus() 返回 false;
场景描述:内嵌外部iframe页面,通过angular 路由跳转到parent window出现上面诡异问题;parent window页面跳转到内嵌iframe的页面正常;
解决方法:判断路由,非iframe路由强制focus button按钮
$("button#focus").get(0).focus();
猜测问题点:document.activeElement当页面没有焦点的时候 默认为 HTMLBodyElement;所以,iframe跳回主页面时并没有焦点;但是主页面跳转到iframe时会自动iframe获取焦点;
- 可以获取焦点的元素(浏览器行为,差异比较大)
- HTMLAnchorElement/HTMLAreaElement with an href
- HTMLInputElement/HTMLSelectElement/HTMLTextAreaElement/HTMLButtonElement but not with
disabled
(IE actually gives you an error if you try), and file uploads have unusual behaviour for security reasons - HTMLIFrameElement (though focusing it doesn''t do anything useful). Other embedding elements also, maybe, I haven''t tested them all.
- Any element with a
tabindex != -1
- div contentEditable = true
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
.box{
width: 100px;
height: 100px;
background-color: #EEEEEE;
display: inline-block;
}
</style>
<script type="text/javascript">
window.onload = function () {
document.onkeyup = function () {
console.log(document.activeElement);
}
}
</script>
</head>
<body>
<divtabindex="-1">tabindex = -1</div>
<divtabindex="2">tabindex = 2</div>
<span> display: block</span>
<divcontenteditable="true">contenteditable="true"</div>
<button disabled>disabled</button>
<button>undisabled</button>
<iframe src="wwww.baidu.com" width="100" height="100"></iframe>
</body>
</html>
java – Window,Document vs. $wnd,$doc
Window and $wnd Document and $doc
除了第一个用于Java而第二个用于JSNI(JavaScript)之外,是否有任何差异?
解决方法
GWT使用$wnd而不是window,因为编译的代码通常在iframe中执行,在这种情况下,window将引用iframe窗口,而$wnd将引用父窗口. $doc也是如此,它是iframe到父文档的引用.
另一方面Document是一个扩展JavaScriptObject的java类,它意味着它是一个Overlay类型,这基本上意味着它是一个原生javascript对象的特殊包装器,它不修改底层JavaScript但添加了一组java方法与它互动.传递给jsni时可以安全地施放.
总之,尽管Document和$doc在java世界中并不相同,但在编译它们时它们是相同的,否则Window它不是$wnd的叠加,它只是一种访问浏览器窗口的某些方法的方法.
虽然GWT编译代码委托给本机js对象和方法,但不要试图找到js和java对象之间的相似之处. GWT设计了一个API来使用一组java对象,小部件,模式等来开发ajax应用程序.一些对象和方法以相同的方式命名,但几乎API都不同.但是,其他项目将java编译为javascript,这两个世界在ST-JS之间具有严格的并行性,而GWT提供了一个名为Elemental的实验库,其API几乎与javascript相同(它仅适用于Chrome).
java – 如何在windows7中以管理员身份进行复制
欢迎任何安装更新的替代解决方案.
解决方法
>在Windows资源管理器中,右键单击指定的文件夹.>转到属性>单击“安全”选项卡>点击编辑…>根据需要更改权限
今天关于JMenu在Windows7 LAF Java7中使用focuslost事件和java中jmenuitem的介绍到此结束,谢谢您的阅读,有关c# – 如何在Windows商店(WinRT)应用程序中启用DocumentsLibrary功能?、document.hasFocus() & $(window).blur()、java – Window,Document vs. $wnd,$doc、java – 如何在windows7中以管理员身份进行复制等更多相关知识的信息可以在本站进行查询。
本文标签: