如何将Java JFrame部分移出Linux桌面?

时间:2021-09-30 10:33:00

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.

我正在编写一个带有可移动框架的Java应用程序,我在Linux中遇到了一个怪癖。我在CentOS下运行GNOME 2.16.0。

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.

当我使用JFrame.setBounds将边界设置为离屏幕一半的任何位置时,它实际上将帧的位置设置为尽可能接近指定的边界,同时仍然完全保留在屏幕上。

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

我怎么告诉Java告诉GNOME实际把帧放到我指定的位置,即使它离屏幕一半?

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.

下面是一些演示问题的示例代码,假设-50,50是屏幕外的。框架仍然可以通过标题栏拖出屏幕,但是对setLocation或setBounds的任何调用都不起作用。

This works fine in Windows.

这在Windows中运行良好。

JFrame frame = new JFrame();
frame.setPreferredSize(new Dimension(200, 200));
frame.pack();
frame.setVisible(true);
frame.setLocation(-50, 50);

1 个解决方案

#1


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.

我不认为在Java中这是可能的,但我很高兴被证明是错的。我将其视为一项功能,旨在降低失去窗户的风险。类似的事情发生在Mac OS X和Ubuntu上。这是修修补补的原始例子。也许有人可以在Windows上试试。

#1


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.

我不认为在Java中这是可能的,但我很高兴被证明是错的。我将其视为一项功能,旨在降低失去窗户的风险。类似的事情发生在Mac OS X和Ubuntu上。这是修修补补的原始例子。也许有人可以在Windows上试试。