[英]Why should I use JLabel instead of Image?
Are there any advantages of using JLabel over Image?
与图像相比,使用JLabel有什么优势?
If all you want to do is display an image at its actual size then use a JLabel so you don't reinvent the wheel. 如果您要做的只是以实际大小显示图像,请使用JLabel,这样就不必重新发明轮子了。
And when I should use Image?
当我应该使用图像?
If you want to customize the painting of the image. 如果要自定义图像的绘画。 Maybe to do dynamic scaling, tiling, rotations etc.
也许要进行动态缩放,平铺,旋转等。
An Image
is not a Swing component but a JLabel
with an ImageIcon
is. Image
不是Swing组件,而是带有ImageIcon
的JLabel
。 So when you want to place your Image
to a regular Swing container you have to use a JLabel
. 因此,当您要将
Image
放置在常规的Swing容器中时,必须使用JLabel
。 But there are other ways to decorate an Image
to become a Component
, JXImagePanel
from the SwingX project is an example. 但是还有其他方法可以装饰一个
Image
使其成为一个Component
,来自SwingX项目的JXImagePanel
是一个示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.