Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java jar文件显示图标_Java_Jar - Fatal编程技术网

Java jar文件显示图标

Java jar文件显示图标,java,jar,Java,Jar,我试图更改通过Eclipse导出的jar文件的显示。在网上搜索后,我发现以下代码: "frmPos.setIconImage( new imageIcon( getClass().getClassLoader().getResource( "PATH/TO/YourImage.png" ) ) );" 但它不起作用,它给了我“此错误”描述资源路径位置类型 imageIcon无法解析为类型window_layout.java/PostOffice/src line 150 java Proble

我试图更改通过Eclipse导出的jar文件的显示。在网上搜索后,我发现以下代码:

"frmPos.setIconImage( new imageIcon( getClass().getClassLoader().getResource( "PATH/TO/YourImage.png" ) ) );"
但它不起作用,它给了我“此错误”描述资源路径位置类型 imageIcon无法解析为类型window_layout.java/PostOffice/src line 150 java Problem”。谁能告诉我我做错了什么?我是否将更改jar图标的代码放错了位置?下面是我的代码示例。谢谢

import java.awt.EventQueue;


public class window_layout {

    private JFrame frmPos;
    private ArrayList<Shipment> shipment_list;
    private Shipment temp;

    private boolean international_destination_bl;
    private boolean priority_bl;
    private int domestic_counter;
    private int international_counter;
    private String shipment_type;
    private float weight;
    private int postal_code;
    private String country;
    private float domestic_total_cost;
    private float international_total_cost;
    private int shipments_counter;

    private String str_weight = "Βάρος:";
    private String text = null;

    private boolean JComboBox_bl;
    private boolean JComboBox_1_bl;
    private boolean JComboBox_2_bl;
    private boolean JComboBox_3_bl;

    private JFrame border;
    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;

    private JTextPane textPane_3;
    private JTextPane textPane_5;

    private JComboBox comboBox;
    private JComboBox comboBox_1;
    private JComboBox comboBox_2;
    private JComboBox comboBox_3;
    private JTextField textField_3;

    private TextArea messageBox;




    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    window_layout window = new window_layout();
                    window.frmPos.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }


    /**
     * Create the application.
     */
    public window_layout() 
    {
        initialize();

        shipment_list = new ArrayList<Shipment> ( );

        international_destination_bl = false;
        domestic_counter = 0;
        international_counter = 0;
        weight = 0;
        postal_code = 0;
        domestic_total_cost = 0;
        international_total_cost = 0;
        shipments_counter = 0;

        JComboBox_bl = false;
        JComboBox_1_bl = false;
        JComboBox_2_bl = false;
        JComboBox_3_bl = false;


    }

    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    // Initialize the contents of the frame.

    private void initialize() 
    {
        frmPos = new JFrame();
        frmPos.setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\Christos\\workspace\\PostOffice\\Envelope_64x64.png"));
        frmPos.setTitle("e - Post Office");
        frmPos.getContentPane().setBackground(new Color(255, 255, 255));
        frmPos.setBounds(100, 100, 448, 438);
        frmPos.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frmPos.getContentPane().setLayout(null);

//*** CODE WHICH CHANGES THE ICON OF THE JAR FILE *** 
            frmPos.setIconImage( new imageIcon( getClass().getClassLoader().getResource( "Envelope_64x64.png" ) ) );
导入java.awt.EventQueue;
公共类窗口布局{
私有JFrame-frmPos;
专用ArrayList装运清单;
私人运输温度;
私人布尔国际目的地;
私有布尔优先权;
私家内勤柜台;
私人国际柜台;
私有字符串类型;
私人浮重;
私人国际邮政编码;
私人国家;
私人浮动国内总成本;
私人浮动国际总成本;
私人柜台;
私有字符串str_weight=“Βάρος;”;
私有字符串文本=null;
私有布尔JComboBox_bl;
私有布尔JComboBox_1_bl;
私有布尔JComboBox_2_bl;
私有布尔JComboBox_3_bl;
私有框架边界;
私有JTextField textField;
私有JTextField textField_1;
私有JTextField textField_2;
专用JTextPane textPane_3;
专用JTextPane textPane_5;
专用JComboBox组合框;
专用JComboBox组合框_1;
专用JComboBox组合框2;
专用JComboBox组合框3;
私有JTextField textField_3;
私有文本区消息框;
/**
*启动应用程序。
*/
公共静态void main(字符串[]args){
invokeLater(新的Runnable(){
公开募捐{
试一试{
窗口布局窗口=新窗口布局();
window.frmPos.setVisible(true);
}捕获(例外e){
e、 printStackTrace();
}
}
});
}
/**
*创建应用程序。
*/
公共窗口_布局()
{
初始化();
发货清单=新的阵列列表();
国际目的地=假;
国内_计数器=0;
国际_计数器=0;
权重=0;
邮政编码=0;
国内总成本=0;
国际总成本=0;
装运数量(单位)计数器=0 ;;
JComboBox_bl=假;
JComboBox_1_bl=假;
JComboBox_2_bl=假;
JComboBox_3_bl=假;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//初始化框架的内容。
私有void初始化()
{
frmPos=新的JFrame();
frmPos.setIconImage(Toolkit.getDefaultToolkit().getImage(“C:\\Users\\Christos\\workspace\\PostOffice\\Envelope_64x64.png”);
frmPos.setTitle(“电子邮局”);
frmPos.getContentPane().setBackground(新颜色(255、255、255));
frmPos.立根(100100448438);
frmPos.setDefaultCloseOperation(JFrame.EXIT\u ON\u CLOSE);
frmPos.getContentPane().setLayout(null);
//***更改JAR文件图标的代码***
frmPos.setIconImage(新的图像图标(getClass().getClassLoader().getResource(“信封_64x64.png”));

您希望此代码具体做什么?Java代码如何更改jar文件的图标?您是否阅读了JFrame.setIconImage()的文档?jar中的png文件在哪里?png文件与项目和jar文件位于同一文件夹中。