更新时间:2023-12-05 20:22:58
使用paintComponent(Graphics g)更好吗?
Is it better to use paintComponent(Graphics g)?.
如果要让图像显示在其他组件的后面,否则将其显示在JLabel
中.这里的问题很可能是您正在访问嵌入式应用程序资源,就像它是File
一样.嵌入式资源必须通过URL
访问.
It is if you want the image to appear behind other components, otherwise display it in a JLabel
. The problem here is most likely that you are accessing an embedded application resource as if it were a File
. Embedded resources must be accessed via URL
.
URL urlToImage = this.getClass().getResource("/images/BrokenFrameResized.jpg");
ImageIcon icon = new ImageIcon(urlToImage);
...