当前位置: 技术问答>java相关
谁能让图片随 Frame 的大小变化自动适应窗口,帮帮我
来源: 互联网 发布时间:2015-11-06
本文导语: 同上 | 呵呵我原来是扩展JPanel的 public class ImageBgPanel extends JPanel { private ImageIcon bg; public ImageBgPanel(LayoutManager layout,ImageIcon icon) { super(layout); bg = icon; } public void...
同上
|
呵呵我原来是扩展JPanel的
public class ImageBgPanel extends JPanel {
private ImageIcon bg;
public ImageBgPanel(LayoutManager layout,ImageIcon icon) {
super(layout);
bg = icon;
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Image img = bg.getImage();
g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
}
}
你不如在JFrame上面放一个JPanel
public class ImageBgPanel extends JPanel {
private ImageIcon bg;
public ImageBgPanel(LayoutManager layout,ImageIcon icon) {
super(layout);
bg = icon;
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Image img = bg.getImage();
g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
}
}
你不如在JFrame上面放一个JPanel