[英]icon in JTabbedPane is not shown
我的標簽有問題:
JTabbedPane tab = new JTabbedPane();
frame.add(tab, BorderLayout.CENTER);
JPanel contact = new JPanel();
contact.add(backgroundContact);
tab.add("Contacto", contact);
//tab.addTab("Contacto",new ImageIcon("images/image2.gif"), contact,"");
JPanel schedule = new JPanel();
schedule.add(backgroundSchedule);
tab.add("Horario", schedule);
//tab.addTab("Horario", new ImageIcon("images/image2.gif"), schedule,"");
JPanel cost = new JPanel();
cost.add(backgroundCost);
tab.add("Tarifas", cost);
//tab.addTab("Tarifas", new ImageIcon("images/image3.gif"), cost,"");
// Los iconos
tab.setIconAt(0, new ImageIcon("images/image1.gif"));
tab.setIconAt(1, new ImageIcon("images/image2.gif"));
tab.setIconAt(2, new ImageIcon("images/image3.gif"));
我嘗試了這兩個選項,但未顯示圖標。 為什么會這樣呢?
我也嘗試過: new ImageIcon("images/im.gif")
不存在,我沒有任何錯誤
嘗試以下方法:
URL urlToImage3 = this.getClass().getResource("/" + "images/image3.gif");
... new ImageIcon(urlToImage3);
您可以將"/" + "images/image3.gif"
串聯"/" + "images/image3.gif"
-我只是想突出顯示/
,因為從類路徑的根目錄搜索更健壯。
如果我懷疑這些圖像是“嵌入式資源”,則File
在運行時將不可用,但應位於應用程序的一個Jars中的類路徑上,因此可以通過URL
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.