[英]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.