简体   繁体   English

为什么要使用JLabel代替Image?

[英]Why should I use JLabel instead of Image?

I always see people loading an image into a JLabel . 我总是看到人们将图像加载到JLabel中 Are there any advantages of using JLabel over Image ? 图像相比,使用JLabel有什么优势吗?

And when I should use 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组件,而是带有ImageIconJLabel 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.

相关问题 我为什么要经常使用||而不是|和&&代替&? - Why should I always use || instead of | and && instead of &? 为什么我应该在addActionListener之前定义一个JLabel? - Why I should define a JLabel before a addActionListener? 为什么我应该在Java中使用序列化而不是文件I / O - Why should i use Serialization instead of File I/O in java 为什么我应该使用formlayout / formdata而不是setBounds? - Why should I use formlayout/formdata instead of setBounds? 为什么我应该为ServletContext使用setInitParameter()而不是setAttribute()? - Why should I use setInitParameter() instead of setAttribute() for ServletContext? 为什么我应该使用通用类而不是特定类 - Why should I use general classes instead of specific classes 为什么我应该使用gRPC而不是IPC / Simple websocket? - Why should I use gRPC instead of IPC / Simple websocket? 为什么 DocumentFile 这么慢,我应该改用什么? - Why is DocumentFile so slow, and what should I use instead? 为什么我的JLabel无法产生图像? - why is my JLabel not producing an image? 我为什么要在循环中使用foreach而不是for(int i = 0; i <length; i ++)? - Why should I use foreach instead of for (int i=0; i<length; i++) in loops?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM