gpt4 book ai didi

Java 设置窗口的 "Document"

转载 作者:行者123 更新时间:2023-12-02 06:29:29 26 4
gpt4 key购买 nike

在某些Mac应用程序中,当打开文档时,窗口的标题将成为文档名称,并且窗口将具有图标。右键单击标题会显示该文件的路径。我想知道是否有办法在 Java 中做到这一点。

enter image description here

最佳答案

您可以通过设置 JFrame 的 rootPane 的 "Window.documentFile" 客户端属性来实现此目的。来自 https://developer.apple.com/library/mac/technotes/tn2007/tn2196.html#WINDOW_DOCUMENTFILE :

Window.documentFile

Type: java.io.File

Applies to: JRootPane

This property adds a document proxy icon to the title bar of the window. This icon is the effective representation of the document that can be dragged and dropped into the Finder or the Dock. Command-clicking on the title will present the full path to the document in a popup. The proxy icon in the title bar will have the icon of document as presented by LaunchServices in the Finder or Open and Save dialog boxes. This property can be changed at anytime throughout the lifetime of the window.

示例代码:

public void open(File file) {
JFrame frame = new JFrame("My App");
frame.getRootPane().putClientProperty("Window.documentFile", file);
frame.getRootPane().putClientProperty("Window.documentModified", false);

// Load file
}

关于Java 设置窗口的 "Document",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20205451/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com