Image image = GenerateImage.toImage(true); //this generates an image file
JLabel thumb = new JLabel();
thumb.setIcon(image)
最佳答案
您必须向 JLabel 提供一个 Icon
实现(即 ImageIcon
)。您可以通过 setIcon
方法(如您的问题)或通过 JLabel
构造函数:
Image image=GenerateImage.toImage(true); //this generates an image file
ImageIcon icon = new ImageIcon(image);
JLabel thumb = new JLabel();
thumb.setIcon(icon);
我建议您阅读 JLabel
的 Javadoc , Icon
, 和 ImageIcon
.另外,您可以查看How to Use Labels Tutorial ,了解更多信息。
关于Java:如何将图像添加到 Jlabel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3775373/