Swing/ResolveShortcutsLinkLocation のバックアップ(No.1)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/ResolveShortcutsLinkLocation へ行く。
- 1 (2025-06-09 (月) 00:40:01)
- 2 (2025-06-17 (火) 15:55:16)
- 3 (2025-06-19 (木) 12:41:37)
- 4 (2025-06-19 (木) 12:43:47)
- category: swing folder: ResolveShortcutsLinkLocation title: JTreeで表示したフォルダ構造でWindowsのlnkショートカット先に移動する tags: [JFileChooser, JTree, File, WindowsLookAndFeel] author: aterai pubdate: 2025-06-09T00:31:20+09:00 description: JTreeを使用して作成したフォルダ構造のTreeNodeがWindowsのlnkショートカットの場合、JFileChooserのShellFolderを利用してリンク先フォルダに移動可能にします。 image: https://drive.google.com/uc?id=1GJkQrkphv_RF2UiMWmc-6wkSimFmnpQu
Summary
JTreeを使用して作成したフォルダ構造のTreeNodeがWindowsのlnkショートカットの場合、JFileChooserのShellFolderを利用してリンク先フォルダに移動可能にします。
Screenshot

Advertisement
Source Code Examples
private File getRealFile8(File file) {
try {
ShellFolder sf = ShellFolder.getShellFolder(file);
if (sf.isLink()) {
file = sf.getLinkLocation();
}
} catch (FileNotFoundException ex) {
file = null;
}
return file;
}
// private File getRealFile9(File file) {
// if (fileSystemView.isLink(file)) {
// try {
// file = fileSystemView.getLinkLocation(file);
// } catch (FileNotFoundException ex) {
// file = null;
// }
// }
// return file;
// }
// private File getRealFile(File file) {
// String version = System.getProperty("java.specification.version");
// if (Double.parseDouble(version) >= 9.0) {
// file = getRealFile9(file);
// } else {
// file = getRealFile8(file);
// }
// return file;
// }
View in GitHub: Java, KotlinExplanation
Java 8
とそれ以前の場合:ShellFolder#isLink()
でリンクファイルかどうかをチェック可能ShellFolder#getLinkLocation()
でで指定されたリンクファイルが参照する通常のファイル(ShellFolder
)を取得可能WindowsLoodAndFeel
環境のJFileChooser
ではShellFolder
を実装したsun.awt.shell.Win32ShellFolder2
でリンク先ファイルを取得している
Java 9
以降の場合:
Reference
- [JDK-8081722] Provide public access to sun.awt.shell.ShellFolder methods which are required for implementing javax.swing.JFileChooser - Java Bug System
- FileSystemView#isLink(File) (Java SE 9 & JDK 9)
- FileSystemView#getLinkLocation(File) (Java SE 9 & JDK 9)
- Links, Symbolic or Otherwise (The Java™ Tutorials > Essential Java Classes > Basic I/O)
- Files#readSymbolicLink(Path) (Java Platform SE 8)