3

我想知道是否有某种用于 Java (Swing) 的 API 库允许您的程序告诉系统它刚刚打开了一个文件,以便它可以将其添加到任何操作系统的用户最近的文档中(如 Windows 的 SHAddToRecentDocs)。这样的事情存在吗?注意:我不考虑将j7Goodies作为解决方案。

编辑:有问题的文件我已经打开了,我不希望系统打开它。我还在我的程序中跟踪最近的文档,我想知道如何告诉系统我打开了它,而不需要系统指示默认程序打开它。

4

1 回答 1

3

The class java.awt.Desktop includes an open() method that does this on Mac OSX. You'll want to test on your other target platforms. If you can't use the feature directly, this earlier incarnation of the API may suggest an approach.

Absent a better implementation, this FileMenu can be used within an application. Also, consider one of the persistence mechanisms mentions here.

Addendum: Internally, java.awt.Desktop delegates to an instance of a platform-specific java.awt.peer.DesktopPeer for each supported platform. You might be able to leverage the approach taken in existing implementations for the platforms you intend to support.

于 2013-03-22T01:18:56.993 回答