java图标是哪一个

Python022

java图标是哪一个,第1张

是咖啡。

当时Java的开发者原本想注册ock(橡树)商标,但是不幸被别人用过了。所以改用Java(一种爪哇产品的咖啡),Java的开发人员非常喜欢喝这种咖啡,也寓意着为全世界献上一杯香气四溢的咖啡。

因此才有了这个咖啡图标的诞生。

java可使用FileSystemView和ShellFolder类获取文件的小图标和大图标,以下是详细代码:

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:/sheet1.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)

    }

}

在mac下启动tomcat,会在任务栏出现一个java图标,右键退出,tomcat服务也会终止。作为一个强迫症,一定要想办法隐藏这个图标

打开tomcat目录,找到conf/catalina.properties文件,加入以下配置

java.awt.headless=true

cd xxx/tomcat/confecho "java.awt.headless=true" >>catalina.properties

完成以上配置,再启动tomcat就不会再出现图标了

链接:https://www.jianshu.com/p/8cdc91bc5d27