简体   繁体   English

在 Mac 上制作 JFrame 透明中断滚动

[英]Making JFrame transparent breaks scrolling on Mac

I have a transparent undecorated JFrame that I set using AWTUtilities.setWindowOpaque(this, false) .我有一个透明的未修饰的JFrame ,我使用AWTUtilities.setWindowOpaque(this, false)设置了它。 On the JFrame , I have a scrollpane;JFrame ,我有一个滚动窗格; it works perfectly on Windows. On the Mac, the whole JFrame is draggable;它在 Windows 上完美运行。在 Mac 上,整个JFrame是可拖动的; so when I try to scroll through the scrollpane by clicking and holding the mouse on the scrollbar, the entire frame moves instead of the scrollbar thumb.因此,当我尝试通过单击并按住滚动条上的鼠标来滚动滚动窗格时,整个框架会移动而不是滚动条拇指。 I also tried to use setBackground(new Color(0,0,0,0)) instead of setWindowOpaque() , but it has the same problem.我也尝试使用setBackground(new Color(0,0,0,0))而不是setWindowOpaque() ,但它有同样的问题。 Any ideas on how to fix this?有想法该怎么解决这个吗?

As suggested in this similar thread , try:正如在这个类似的线程中所建议的那样,尝试:

getRootPane().putClientProperty("apple.awt.draggableWindowBackground", Boolean.FALSE);

If you choose to use this, the scrollbar will be usable and the window won't drag.如果您选择使用它,滚动条将可用并且 window 不会拖动。 However, you may be stuck with an immovable window, unless you add a MouseMotionListener and move the window around in the mouseDragged() method using a call like frame.setLocation() .但是,您可能会遇到无法移动的 window,除非您添加MouseMotionListener并使用 frame.setLocation frame.setLocation() ) 之类的调用在mouseDragged()方法中移动 window。

Instead, you might be able to force the user to click on the scrollbar's arrow buttons, rather than drag the scrollbar itself... But that's not the most user-friendly idea I've ever seen.相反,您可以强制用户单击滚动条的箭头按钮,而不是拖动滚动条本身……但这不是我见过的最人性化的想法。

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

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