[英]How to hide mouse cursor using JOGL2?
我正在使用JOGL2和NativeWindow API來編寫Java應用程序。 隱藏鼠標光標的最佳/最簡單方法是什么?
[編輯]我沒有使用JFrame創建窗口,而是使用JOGL的GLWindow。 GLWindow沒有setCursor方法。 這還有可能嗎?
正如你(thekidder)所說GLWindow
沒有那種能力所以我會在這樣的Frame
(或JFrame
)中使用GLCanvas
(就像AlexR寫的那樣):
public static void main(String... args) {
// create the cursor
Toolkit t = Toolkit.getDefaultToolkit();
Image i = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
Cursor noCursor = t.createCustomCursor(i, new Point(0, 0), "none");
// try it with a normal frame
Frame f = new Frame();
// create the GLCanvas and add it to the frame
GLCanvas canvas = new GLCanvas();
frame.add(canvas);
f.setCursor(noCursor);
f.setSize(400, 200);
f.setVisible(true);
}
這已經在JOGL2中使用NEWT(一個GLWindow對象)實現。 請參閱https://jogamp.org/bugzilla/show_bug.cgi?id=409 (在thekidder的答案中引用)。
你可以這樣做:
glWindow.setPointerVisible(false);
如果鼠標位於應用程序窗口區域,則可以將任何圖像設置為自定義光標。 使用透明圖像1x1像素。 我用它 - 工作正常。 它是常規API,沒有JOGL,沒有本機代碼。
目前在NEWT GLWindow:
window = GLWindow.create(caps);
...
window.requestFocus();
window.setAlwaysOnTop(true); // i think, be on top is good than mouse is jailed
window.setUndecorated(true); // remove window borders (if u want)
window.setPointerVisible(false); // hide cursor
window.confinePointer(true); // jail inside (cursor will be limited to window borders)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.