更新时间:2023-12-05 10:35:40
我在Google中寻找代码段,最终得到了一个解决方案...并且所采用的模式与以前的注释所引用的模式相同. 给我解决方案的代码是:
Looking for pieces of code in Google I ended up with a solution... And was applying the same pattern that previous comments refer. The code that gave me the solution was:
label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/gray.png")))
然后,我制作了要实现的方法:
With that, I made then the method that I wanted to implement:
private static void DisplayImage(JPanel jp, String url) {
JLabel jl=new JLabel();
jl.setIcon(new javax.swing.ImageIcon(getClass().getResource(url)));
jp.add(jl);
}
也许这不是完美且最正确的解决方案,但对我来说却是完美的,这就是我想要的.
Maybe this is not the perfect and most-correct solution, but works perfect to my, that is what I want.
谢谢大家的回答和建议!
Thanks all for the answers and suggestions!