在Java中保留屏幕边缘
如何制作一个窗口(例如 java.awt.Frame
、javax.swing.JFrame
、java.awt.Dialog
、< code>javax.swing.JDialog 等)保留屏幕边缘,比如 Dock、任务栏、Trillian 或 Microsoft OneNote 可以吗?如果可能的话,我的目标是只使用标准 JDK 库。
How can I make a window (such as a java.awt.Frame
, javax.swing.JFrame
, java.awt.Dialog
, javax.swing.JDialog
, etc.) reserve the edge of the screen, like a dock, taskbar, Trillian, or Microsoft OneNote can? I aim to only use standard JDK libraries if possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这种行为是 Windows 操作系统特有的,因此在标准 JDK 或 AWT/Swing 中无法做到这一点,因为它们需要在许多不同的操作系统上一致地工作。
与您想要的最接近的等效方法是获取当前屏幕的边界并移动/调整窗口大小以使其与一侧齐平,尽管这现在会对桌面或其他窗口产生任何影响。
您可能会得到的最接近您想要的东西是使用 JNIWrapper 和 WinPack 来更改本机窗口行为。不过,他们的文档没有显示有关桌面工具栏的任何内容。您可能必须使用他们的 JNI 直接访问特定的 COM 函数,然后了解如何在 C++ 中执行此操作,但如果您不了解 C++,那可能超出了您的项目范围。
附录:
如果您想使用特定操作系统和桌面管理器的本机功能,您将需要连接本机 C++ 库以连接到 Gnome、KDE、Mac OS 等。 “Java JNI”和您想要集成的窗口系统以查找可以使用的包。例如,对于 Gnome,请参阅此处。
如果您想支持多个操作系统,请确保创建一个通用接口,以便您可以根据运行时可用的 JNI 进行与相应 JNI 连接的实现,并在没有可用的情况下允许回退。
附言。如果您希望在应用程序中弹出通知,Mac OS 和各种 Linux 版本都支持 Growl,这样可以节省您一些时间。
This behaviour is very specific to the Windows operating system, and as such there is no way to do this in the standard JDK or with AWT/Swing, since these need to work consistently across a number of different operating systems.
The closest equivalent to what you want is to get the current screen's boundaries and move/resize your window to fit flush against one side, although this will now have any effect on the desktop or other windows.
The closest thing you will probably get to what you want is by using JNIWrapper and WinPack to alter the native window behaviour. Their documentation doesn't show anything about desktop toolbars, though. You would probably have to use their JNI to access the specific COM functions directly and then find out how to do it in C++, but if you don't know C++, that's probably out of the scope of your project.
Addendum:
If you want to make use of the native features for specific operating systems and desktop managers, you will need to connect with a native C++ library to hook into Gnome, KDE, Mac OS etc. Search for 'Java JNI' and the windowing system you want to integrate with to find packages you can use. For instance, for Gnome, see here.
If you want to support multiple operating systems, make sure you create a common interface so you can make implementations that connect with the respective JNIs depending on which one is available at runtime, and allow fallback if none of them are available.
PS. If you want popup notifications in your app, Mac OS and various Linux builds support Growl so that can save you some time.
您可以使用 JMenu 源中的 Toolkit.getDefaultToolkit().getScreenInsets()
You can use Toolkit.getDefaultToolkit().getScreenInsets() From JMenu sources