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?
Asked
Active
Viewed 482 times
6
trashgod
- 203,806
- 29
- 246
- 1,045
user1309036
- 61
- 1
- 1
- 4
-
What is your JRE version, is it 1.7 ? – nIcE cOw Apr 04 '12 at 14:08
-
You might try setting the background to almost-transparent, e.g. Color(0,0,0,10) or so (not certain of the exact threshold). – technomage Apr 04 '12 at 14:39
-
It seems like any kind of transparency breaks it. I tried Color(0,0,0,.99f) and it doesn't work. – user1309036 Apr 04 '12 at 14:47
-
@user1309036 : So sorry, can not test that, since I am using Windows :-( – nIcE cOw Apr 04 '12 at 15:23
-
1It's a usability feature for undecorated frames, which would otherwise be immoveable. See also this [example](http://stackoverflow.com/a/2166500/230513). – trashgod Apr 04 '12 at 16:09
-
2If you _don't_ click, does the mouse wheel scroll the content? – trashgod Jun 17 '12 at 03:25
-
Do you have some sample code I can try? – MadProgrammer Jul 22 '12 at 08:57
1 Answers
1
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.
Community
- 1
- 1
cyanpelican
- 11
- 4