在网上看到人家说是用JLabel可以实现,但是我不知道怎么实现
请教高手。。谁有源码是最好的,谢谢!!!

解决方案 »

  1.   

    用到了层的概念。
    bgLable.setIcon(backgroundIcon);
    getContentPane().add(bgLabel,-1);                // 在最底层加一个带背景图的JLabel
    getContentPane().add(yourContentPanel,0);        // 在顶层添加你的组件如果添加的组件是JPanel,要把JPanel设置为透明的。panel.setOpaque(false);
      

  2.   

    /*
     * Background.java
     *
     * Created on 2005年7月25日, 下午3:40
     *//**
     *
     * @author  Administrator
     */
    public class Background extends javax.swing.JFrame {
        
        /** Creates new form Background */
        public Background() {
            initComponents();
        }
        
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        private void initComponents() {
            jLabel1 = new javax.swing.JLabel();        addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
                }
            });        jLabel1.setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\Administrator\\My Documents\\My Pictures\\Sample.jpg"));//楼主要的背景文件路径
            jLabel1.setText("jLabel1");
            getContentPane().add(jLabel1, java.awt.BorderLayout.CENTER);        pack();
        }
        
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
        }
        
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            new Background().show();
        }
        
        
        // Variables declaration - do not modify
        private javax.swing.JLabel jLabel1;
        // End of variables declaration
        
    }