Java JOptionPane背景图像
如何设置JOptionPane的背景图像?我想在JOptionPane的背景上显示不同的图像。您可以扩展JOptionPane类并重写paint方法 编辑: 根据图像的分辨率和质量,在WindowResize事件期间,您可能能够使用仿射变换拉伸图像,而不会产生太大的失真。这将允许您处理下面提到的JOptionPane和图像大小差异Java JOptionPane背景图像,java,image,background,joptionpane,Java,Image,Background,Joptionpane,如何设置JOptionPane的背景图像?我想在JOptionPane的背景上显示不同的图像。您可以扩展JOptionPane类并重写paint方法 编辑: 根据图像的分辨率和质量,在WindowResize事件期间,您可能能够使用仿射变换拉伸图像,而不会产生太大的失真。这将允许您处理下面提到的JOptionPane和图像大小差异 class ImageBackgroundPane extends JOptionPane { private BufferedIma
class ImageBackgroundPane extends JOptionPane
{
private BufferedImage img;
public ImageBackgroundPane (BufferedImage image)
{
this.img = image;
}
@Override
public void paint(Graphics g)
{
//Pick one of the two painting methods below.
//Option 1:
//Define the bounding region to paint based on image size.
//Be careful, if the image is smaller than the JOptionPane size you
//will see a solid white background where the image does not reach.
g.drawImage(img, 0, 0, img.getWidth(), img.getHeight());
//Option 2:
//If the image can be guaranteed to be larger than the JOptionPane's size
Dimension curSize = this.getSize();
g.drawImage(img, 0, 0, curSize.width, curSize.height, null);
//Make sure to paint all the other properties of Swing components.
super.paint(g);
}
}
我也在寻找解决办法,你找到什么了吗?