将图像渲染到标签中 [英] Rendering Image into label
本文介绍了将图像渲染到标签中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个标签.我想将图像渲染到其中.但是下面的代码可以做任何事情.
I have a label. I want to render image into it. But the following code would do anything.
CardLayout cl = (CardLayout) (mainPanel.getLayout());
cl.show(mainPanel, "newPersonaCard");
BufferedImage myPicture = ImageIO.read(new File("C:\\Desktop\\Documents\\Pictures\\always.jpg"));
ImageIcon icon = new ImageIcon(myPicture);
icon.getImage().flush();
我正在使用netbean设计器.
I am using netbean designer.
推荐答案
您是正确的,在某些情况下,在JLabel
中重新绘制Icon
存在问题,那么您必须致电
You are right, in some cases there issue with repainting Icon
in the JLabel
, then you have to call,
myIcon.getImage().flush();
myLabel.setIcon(myIcon);
其余方法已在Icon
和JLabel
中正确实现
rest of methods is implemented in the Icon
and JLabel
correctly
这篇关于将图像渲染到标签中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文