7

I'm writing a Java application with movable frames, and I've come across a quirk in Linux. I'm running GNOME 2.16.0 under CentOS.

When I use JFrame.setBounds to set the bounds to any location that's half off the screen, it actually sets the location of the frame to be as close as possible to the bounds specified while still staying completely on the screen.

How do I tell Java to tell GNOME to actually put the frame where I specify, even if that's half off the screen?

Here's some sample code that demonstrates the problem, assuming that -50, 50 is off-screen. The frame can still be dragged off the screen by the title bar, but any calls to setLocation or setBounds don't work.

This works fine in Windows.

JFrame frame = new JFrame();
frame.setPreferredSize(new Dimension(200, 200));
frame.pack();
frame.setVisible(true);
frame.setLocation(-50, 50);
Erick Robertson
  • 32,125
  • 13
  • 69
  • 98
  • Ahh joys of Java UI not behaving the same on all platforms... I'd say the answer is likely not on Java's side, but I may be wrong (hence the comment rather than answer) :) – Romain Mar 23 '10 at 23:40

1 Answers1

3

I don't think it's possible in Java, but I'd enjoy being proved wrong. I see it as a feature, meant to reduce the risk of lost windows. A similar thing happens on Mac OS X and Ubuntu. Here's a primitive example for tinkering. Maybe somebody can try in on Windows.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Works fine on Windows XP using JDK6. I used setLocation(-50, 0) and part of the title bar was off the screen. – camickr Mar 24 '10 at 02:36
  • Thank you for looking at this, camickr. As Romain Muller suggests, this may be implementation dependent. – trashgod Mar 24 '10 at 02:55
  • It's odd that I can drag the frame half off the screen, but I can't use setBounds to put it there. I'm still looking for a workaround to this. In the meantime, I think I'll check to see if the system property java.awt.graphicsenv is set to sun.awt.Win32GraphicsEnvironment, since this is the only one where it appears you can actually set a frame half off-screen. If it's not, then I can adjust my logic to not even try to move a frame off-screen. – Erick Robertson Mar 24 '10 at 12:38