簡體   English   中英

Java-JFrame不顯示ImageIcon

[英]Java - JFrame not displaying ImageIcon

public Vue(String title) {
    super(title);



    this.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    this.getContentPane().setLayout(new GridLayout(4, 1));
    JPanel p1 = createPanel1();
    this.getContentPane().add(p1);
    JPanel p2bis = createPanel2bis();
    this.getContentPane().add(p2bis);
    JPanel p3 = createPanel3();
    this.getContentPane().add(p3);




    this.setJMenuBar(createMenuBar());

    this.setPreferredSize(new Dimension(750,400));
    this.pack();
    this.setVisible(true);


    ImageIcon image = new ImageIcon(getClass().getResource("voile.png"));
    this.setIconImage(image.getImage());
    System.out.println(image.getDescription());

}

嗨,

我花了一些時間來找到解決方案,以將我的圖像顯示為JFrame圖標圖像...並且嘗試了很多類似的操作

ImageIcon image = new ImageIcon(Constants.LOGO_ABSOLUTE_PATH);
this.setIconImage(image.getImage());
System.out.println(image.getDescription());

我將“ voile.png”文件放在目錄中的所有位置:root,src,bin以及bin和src包中。 我還嘗試了在線徽標及其URI。

但是,它實際上不起作用。 如果有人可以幫助我?

我正在Eclipse Oxygen和Windows 10上運行它

PS:System.out.println(image.getDescription()); 總是顯示我的圖片所在的路徑(無論如何,到處都放置它)

ImageIcon不支持PNG透明度。 我必須創建一個空白的jpg圖像,然后在其中放置徽標。 我的最終代碼是

ImageIcon image = new ImageIcon(Constants.LOGO);
this.setIconImage(image.getImage());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM