java根據(jù)擴(kuò)展名獲取系統(tǒng)圖標(biāo)和文件圖標(biāo)示例
import java.io.File;
import java.io.IOException;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.BoxLayout;
import javax.swing.filechooser.FileSystemView;
import sun.awt.shell.ShellFolder;
public class FileIconExtractor extends JFrame implements ActionListener{
private JButton getIconBtn = new JButton("get Icon");
private JPanel iconPanel = new JPanel();
private JTextField extField = new JTextField();
private JLabel smallIconLabel = new JLabel("small Icon here");
private JLabel bigIconLabel = new JLabel("big Icon here");
public FileIconExtractor() {
this.setSize(200, 150);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new BorderLayout());
getIconBtn.setActionCommand("GETICON");
getIconBtn.addActionListener(this);
iconPanel.setLayout(new BoxLayout(iconPanel, BoxLayout.Y_AXIS));
iconPanel.add(smallIconLabel);
iconPanel.add(bigIconLabel);
this.add(extField, BorderLayout.NORTH);
this.add(iconPanel, BorderLayout.CENTER);
this.add(getIconBtn, BorderLayout.SOUTH);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("GETICON")) {
String ext = extField.getText();
File file;
try
{
file = File.createTempFile("icon", "." + ext);
FileSystemView view = FileSystemView.getFileSystemView();
Icon smallIcon = view.getSystemIcon(file);
ShellFolder shellFolder = ShellFolder.getShellFolder(file);
Icon bigIcon = new ImageIcon(shellFolder.getIcon(true));
setIconLabel(smallIcon, bigIcon);
file.delete();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
private void setIconLabel(Icon smallIcon, Icon bigIcon) {
smallIconLabel.setIcon(smallIcon);
bigIconLabel.setIcon(bigIcon);
}
public static void main(String[] args) {
FileIconExtractor fie = new FileIconExtractor();
}
}
相關(guān)文章
解決SpringCloud?Feign異步調(diào)用傳參問題
這篇文章主要介紹了SpringCloud?Feign異步調(diào)用傳參問題,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-05-05java定時(shí)任務(wù)框架elasticjob詳解
這篇文章主要介紹了java定時(shí)任務(wù)框架elasticjob詳解,Elastic-Job是ddframe中dd-job的作業(yè)模塊中分離出來的分布式彈性作業(yè)框架。該項(xiàng)目基于成熟的開源產(chǎn)品Quartz和Zookeeper及其客戶端Curator進(jìn)行二次開發(fā)。,需要的朋友可以參考下2019-06-06Java中Object類常用的12個(gè)方法(小結(jié))
Java 中的 Object 方法在面試中是一個(gè)非常高頻的點(diǎn),本文主要介紹了Java中Object類常用的12個(gè)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12Mybatis-Plus或PageHelper多表分頁查詢總條數(shù)不對(duì)問題的解決方法
PageHelper 這個(gè)插件用了很多次了,今天使用的時(shí)候才遇到一個(gè)問題,這篇文章主要給大家介紹了關(guān)于Mybatis-Plus或PageHelper多表分頁查詢總條數(shù)不對(duì)問題的解決方法,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08