gddhy

_(:з」∠)_ 加载中...
  • 主页
  • 归档
  • 工具
  • 关于
所有文章 友链

gddhy

_(:з」∠)_ 加载中...

  • 主页
  • 归档
  • 工具
  • 关于

Java获取文件图标

2024-01-18
字数统计:235字 阅读时长≈1分

转载自Java获取文件图标

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.awt.FlowLayout;
import java.io.File;
import java.io.FileNotFoundException;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.filechooser.FileSystemView;


public class GetFileIcon {

/**
* @param args
*/
public static void main(String[] args) {
String filePath = "D:/luckystar2008/works/QDII/SR/SR_PA02897156-QDII后台估值核算规则优化_任务分配.xlsx";
File f = new File(filePath);
JFrame frm = new JFrame();
frm.setSize(300, 200);
frm.setLocationRelativeTo(null);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setVisible(true);
frm.setLayout(new FlowLayout(10,10,FlowLayout.LEADING));

JLabel sl = new JLabel("小图标");
frm.add(sl);
JLabel bl = new JLabel("大图标");
frm.add(bl);

sl.setIcon(getSmallIcon(f));
bl.setIcon(getBigIcon(f));
}

/**
* 获取小图标
* @param f
* @return
*/
private static Icon getSmallIcon(File f) {
if (f != null && f.exists()) {
FileSystemView fsv = FileSystemView.getFileSystemView();
return fsv.getSystemIcon(f);
}
return null;
}

/**
* 获取大图标
* @param f
* @return
*/
private static Icon getBigIcon(File f) {
if (f!=null && f.exists()) {
try {
sun.awt.shell.ShellFolder sf = sun.awt.shell.ShellFolder.getShellFolder(f);
return new ImageIcon(sf.getIcon(true));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
}

img

赏

谢谢你请我吃糖果

微信

扫一扫,分享到微信

微信分享二维码
流量卡相关
暴风一号 病毒 源码学习
目录,不存在的…
留言已关闭
:gddhy
© gddhy
Hexo Theme Yilia by Litten
  • 所有文章
  • 友链

tag:

  • Android
  • 软件分享
  • game
  • Hexo
  • JavaScript
  • 旧机博物馆
  • MIUI
  • Java
  • git
  • Termux
  • mtk
  • 原神
  • Win
  • Html
  • 安卓学习笔记

    缺失模块

  • Luminous' Home
  • 影子博客
  • 四次元领域
  • 初之音
  • Mr.Pumpkin
  • ZhaoQuinn 's Blog