{"id":975,"date":"2018-04-17T18:59:08","date_gmt":"2018-04-17T09:59:08","guid":{"rendered":"https:\/\/chat-messenger.com\/?p=975"},"modified":"2018-12-23T01:59:03","modified_gmt":"2018-12-22T16:59:03","slug":"get-system-icon","status":"publish","type":"post","link":"https:\/\/chat-messenger.com\/en\/blog\/java\/get-system-icon","title":{"rendered":"Extract Java system icons"},"content":{"rendered":"<h2 class=\"common_title\"><a name=\"0\">Java <strong>system icon<\/strong>Extracting the<\/a><\/h2>\n<p>\n<strong>Java<\/strong>The following is a sample program that extracts icons from a specified file into a png format image file. The specified file can be an executable file with exe extension, dll, xls, doc, or any other file.<\/p>\n<p>I have looked on the Internet for similar methods, but have not found any.<br \/>\nHowever, we have found a really easy way to get it, so we will introduce it here.<br \/>\nThis method is also available on Chat &amp; Messenger,<a href=\"https:\/\/chat-messenger.com\/en\/manual\/messenger_chat\/sticky_note\/\"><strong>Ability to attach files to stickies<\/strong><\/a>We are using this service in the following areas.\n<\/p>\n<h2 class=\"common_title\"><a name=\"1\">Sample program operation check<\/a><\/h2>\n<p><a href=\"http:\/\/hp.vector.co.jp\/authors\/VA045104\/swing_ex\/IconExtractor.jar\"><strong>Run a sample<\/strong><\/a><br \/>\n<br \/><span style=\"font-size:x-small;\">If a jar file is associated, it can be executed.<\/span><\/p>\n<ol>\n<li>Get the sample source, compile and run it.\n<\/li>\n<li>When launched, the main window will open. Drag and drop the icon you wish to extract directly into the window.<br \/>\n<img src=\"https:\/\/chat-messenger.com\/images\/IconExtractor.jpg\" alt=\"Icon Acquisition\" border=\"0\"><\/p>\n<\/li>\n<li>A png-format image file is output to the same location as the original eincon.<br \/>\n<img src=\"https:\/\/chat-messenger.com\/images\/IconExtractor2.jpg\" alt=\"Icon Acquisition\" border=\"0\"><\/p>\n<\/li>\n<\/ol>\n<p><script type=\"text\/javascript\" src=\"https:\/\/chat-messenger.com\/js\/common.js?dd12sssas2223\" charset=\"UTF-8\"><\/script><br \/>\n<script type=\"text\/javascript\"> writePR(); <\/script><\/p>\n<h2 class=\"common_title\"><a name=\"2\">Sample Program Explanation<\/a><\/h2>\n<p>The process of extracting icons in Java is realized in the following way.<\/p>\n<ol>\n<li>\nSet Look &amp; Feel to Windows.<br \/>\nUIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());<\/p>\n<\/li>\n<li>\nDrag-and-drop retrieved files. <strong>JFileChooser.getIcon()<\/strong> method. <strong>Icon<\/strong> object.<\/p>\n<\/li>\n<li>\n<strong>ImageIO.write()<\/strong> method outputs the Icon object to a png image file.<\/p>\n<\/li>\n<\/ol>\n<h2 class=\"common_title\"><a name=\"3\">sample program<\/a><\/h2>\n<p><textarea readonly=\"readonly\" style=\"font-size: 13px;height: 400px;\" class=\"src\" onclick=\"this.focus();this.select()\">import java.awt.BorderLayout;<br \/>\nimport java.awt.Color;<br \/>\nimport java.awt.datatransfer.DataFlavor;<br \/>\nimport java.awt.datatransfer.Transferable;<br \/>\nimport java.awt.dnd.DnDConstants;<br \/>\nimport java.awt.dnd.DropTarget;<br \/>\nimport java.awt.dnd.DropTargetDragEvent;<br \/>\nimport java.awt.dnd.DropTargetDropEvent;<br \/>\nimport java.awt.dnd.DropTargetEvent;<br \/>\nimport java.awt.dnd.DropTargetListener;<br \/>\nimport java.awt.image.BufferedImage;<br \/>\nimport java.io.File;<br \/>\nimport java.util.Iterator;<br \/>\nimport java.util.List;<\/p>\n<p>import javax.imageio.ImageIO;<br \/>\nimport javax.swing.ImageIcon;<br \/>\nimport javax.swing.JFileChooser;<br \/>\nimport javax.swing.JFrame;<br \/>\nimport javax.swing.JLabel;<br \/>\nimport javax.swing.JPanel;<br \/>\nimport javax.swing.SwingConstants;<br \/>\nimport javax.swing.UIManager;<\/p>\n<p>public class IconExtractor extends JFrame<br \/>\n                implements DropTargetListener {<\/p>\n<p>    private JPanel jContentPane = null;<br \/>\n    private JLabel jLabel = null;<br \/>\n    private JFileChooser chooser;<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        IconExtractor extractor = new IconExtractor();<br \/>\n        extractor.setVisible(true);<br \/>\n    }<\/p>\n<p>    public IconExtractor() {<br \/>\n        super();<br \/>\n        try {<br \/>\n            UIManager.setLookAndFeel(<br \/>\n                    UIManager.getSystemLookAndFeelClassName());<br \/>\n            chooser = new JFileChooser();<br \/>\n        } catch (Exception e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n        initialize();<br \/>\n    }<\/p>\n<p>    private void initialize() {<br \/>\n        this.setSize(300, 200);<br \/>\n        this.setContentPane(getJContentPane());<br \/>\n        this.setTitle(\u201cIcon extraction\u201d);<br \/>\n        this.setLocationRelativeTo(null);<br \/>\n        this.setDefaultCloseOperation(EXIT_ON_CLOSE);<br \/>\n    }<\/p>\n<p>    private JPanel getJContentPane() {<br \/>\n        if (jContentPane == null) {<br \/>\n            jLabel = new JLabel();<br \/>\n            jLabel.setText(\u201cDrag the icon.\u201d);<br \/>\n            jLabel.setBackground(Color.white);<br \/>\n            jLabel.setHorizontalAlignment(SwingConstants.CENTER);<br \/>\n            jLabel.setOpaque(true);<br \/>\n            new DropTarget(jLabel,<br \/>\n                    DnDConstants.ACTION_COPY_OR_MOVE, this);<br \/>\n            jContentPane = new JPanel();<br \/>\n            jContentPane.setLayout(new BorderLayout());<br \/>\n            jContentPane.add(jLabel, BorderLayout.CENTER);<br \/>\n        }<br \/>\n        return jContentPane;<br \/>\n    }<\/p>\n<p>    \/\/ \u2014 implements DropTargetListener \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014-<br \/>\n    public void drop(DropTargetDropEvent dtde) {<br \/>\n        dtde.acceptDrop(DnDConstants.ACTION_MOVE);<br \/>\n        try {<\/p>\n<p>            Transferable tran = dtde.getTransferable();<\/p>\n<p>            List fileList = (List) tran<br \/>\n                    .getTransferData(DataFlavor.javaFileListFlavor);<br \/>\n            Iterator iterator = fileList.iterator();<br \/>\n            while (iterator.hasNext()) {<br \/>\n                File file = (File) iterator.next();<br \/>\n                ImageIcon icon = (ImageIcon) chooser.getIcon(file);<br \/>\n                String ext = file.getAbsoluteFile() + \u201c.png\u201d;<br \/>\n                \/\/ Save image file<br \/>\n                ImageIO.write((BufferedImage) icon.getImage(), \u201cpng\u201d,<br \/>\n                        new File(ext));<br \/>\n                jLabel.setText(&ldquo;&lt;html&gt;Extraction completed&lt;br&gt;&rdquo; + ext);<br \/>\n                setIconImage(icon.getImage());<br \/>\n            }<br \/>\n            dtde.dropComplete(true);<br \/>\n        } catch (Exception e) {<br \/>\n            e.printStackTrace();<br \/>\n            dtde.dropComplete(false);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public void dragEnter(DropTargetDragEvent e) {<br \/>\n    }<\/p>\n<p>    public void dragOver(DropTargetDragEvent e) {<br \/>\n    }<\/p>\n<p>    public void dropActionChanged(DropTargetDragEvent e) {<br \/>\n    }<\/p>\n<p>    public void dragExit(DropTargetEvent e) {<br \/>\n    }<br \/>\n}<br \/>\n<\/textarea><\/p>","protected":false},"excerpt":{"rendered":"<p>Extract Java system icon Extract the icon of the specified file to a png format image file using Java [\u2026]<\/p>","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":""},"categories":[19],"tags":[],"_links":{"self":[{"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/posts\/975"}],"collection":[{"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/comments?post=975"}],"version-history":[{"count":5,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/posts\/975\/revisions"}],"predecessor-version":[{"id":1872,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/posts\/975\/revisions\/1872"}],"wp:attachment":[{"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/media?parent=975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/categories?post=975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/tags?post=975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}