简体   繁体   English

在秋千中禁用鼠标

[英]Disabling mouse in Swing

I would like to disable the mouse cursor not the text cursor in my Swing application. 我想在我的Swing应用程序中禁用鼠标光标而不是文本光标。 I found the following code which has managed to hide the cursor but not disabling its function. 我发现以下代码已成功隐藏了光标但未禁用其功能。

// Transparent 16 x 16 pixel cursor image.
BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
// Create a new blank cursor.
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor");
// Set the blank cursor to the JFrame.
getContentPane().setCursor(blankCursor);

Any solution please? 有什么解决办法吗?

Two solutions: 两种解决方案:

  1. You can call on all your components: setEditable(false). 您可以调用所有组件:setEditable(false)。 But actually, even that won't do it perfectly, better to do setEnabled(false). 但是实际上,即使那样做也不能完美,最好执行setEnabled(false)。

  2. If you are using a JFrame, you can use the JLayeredPane's GlassPane. 如果使用的是JFrame,则可以使用JLayeredPane的GlassPane。 Set that to setEnabled(true) and it will intercept all mouse events 将其设置为setEnabled(true),它将拦截所有鼠标事件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM