如何在netbeans IDE中将帧背景设置为图片 [英] How can i set the frame background to a picture in netbeans IDE
本文介绍了如何在netbeans IDE中将帧背景设置为图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
如何在netbeans IDE中将帧背景设置为图片?
i尝试通过设置来实现jlabel的图标,但它不起作用?我得到了小尺寸的jframe(不是实际的)。图像不可见
i也试着去买jpanel.it也有同样的效果。
请给出一个解决方案。
解决方案
你需要画画通过在 JFrame中覆盖 jComponent
的 paintComponent(Graphics g)
方法来自己创建图像/ code>实施。请参阅 javadoc [< a href =http://docs.oracle.com/javase/7/docs/api/javax/swing/JComponent.html#paintComponent(java.awt.Graphics)\"target =_ blanktitle =New Window > ^ ]了解详情
@ Override
protected void paintComponent(Graphics g)
{
Image img = getToolkit()。getImage( filename.png);
// 图片img = getToolkit()。getImage(getClass()。getResource(resource.png) ));
// 绘制图像缩放以适合整个尺寸
g.drawImage(img, 0 , 0 ,getWidth(),getHeight ());
}
作为替代方案,对于图像处理,您可以使用Graphics2D [ ^ ] class。
祝你好运!
Dear All,
How can i set the frame background to a picture in netbeans IDE?
i try to do it by setting icon for jlabel but it is not working?i got the jframe in small size(not actual one).the image is not visble
i also try to do it buy jpanel.it also have same effect.
Please give a solution.
解决方案
You will need to draw the image yourself by overriding thepaintComponent(Graphics g)
method ofJComponent
in yourJFrame
implementation. See the javadoc[^] for details
@Override protected void paintComponent(Graphics g) { Image img = getToolkit().getImage("filename.png"); //Image img = getToolkit().getImage(getClass().getResource("resource.png")); //draw image scaled to fit the entire size g.drawImage(img,0,0,getWidth(),getHeight()); }
As an alternative, for image manipulation you can use the Graphics2D[^] class.
Good Luck!
这篇关于如何在netbeans IDE中将帧背景设置为图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文