Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making JFrame transparent breaks scrolling on Mac

I have a transparent undecorated JFrame that I set using AWTUtilities.setWindowOpaque(this, false). On the JFrame, I have a scrollpane; it works perfectly on Windows. On the Mac, the whole JFrame is draggable; 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. Any ideas on how to fix this?

like image 335
user1309036 Avatar asked Apr 04 '12 14:04

user1309036


1 Answers

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. 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().

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.

like image 102
cyanpelican Avatar answered Nov 10 '22 22:11

cyanpelican