JFrame的ContentPane里画上图片,再在JFrame上放一个透明的JLayeredPane或其他如GlassPane,所有一切就在它上面处理了,事件,截获鼠标键盘。

解决方案 »

  1.   

    kypfos(就当我没上过大学) ,谢了,能不能详细点?
      

  2.   

    可先在LayeredPane上加上图片。再将contentPane设为透明。
      

  3.   

    需要在LayeredPane上处理事件,所以必须把图片画在ContentPane上。
      

  4.   

    contentPane不是在layeredPane的上面吗?
      

  5.   

    private void createBackGround()
    //实现背景图片,放在LayeredPane上
    {
        ImageIcon backGroundImg = new ImageIcon("文件名");
        backGround = getLayeredPane();
        backGroundLabel.setIcon((Icon)backGroundImg); //贴到JLabel上
        backGroundLabel.setBounds( , , ,);            //设图片大小
        backGround.add(backGroundLabel,new Integer(Integer.MIN_VALUE));
                                                      //贴到layeredPane上
    }另外
    ((JPanel)contentPane).setOpaque(false);           //将ContentPane设为透明
      

  6.   

    大哥,我要是在JFrame中加背景图片。不是设置标签。
      

  7.   

    JFrame和JLabel都是容器,带有图片的标签放在ContentPane中,铺开来不就成了背景,其他事情你就在JLabel上操作也行啊先试试代码再说吧。
      

  8.   

    放在ContentPane上是不会成为背景的,你再在ContentPane上添加个按钮,看看结果。
      

  9.   

    在API文档上查rootPane可以看到Pane的层次结构。
    我下课了,大家88先~~~
      

  10.   

    谢谢指教!能够达到我的要求,但是,有没有更好的方法?
    是不是只能加Label?