Setting background images in JFrame

后端 未结 4 1377
余生分开走
余生分开走 2020-11-22 15:49

Are any methods available to set an image as background in a JFrame?

4条回答
  •  北海茫月
    2020-11-22 16:11

    import javax.swing.*;
    
    import java.awt.*;
    
    import java.awt.event.*;
    
    class BackgroundImageJFrame extends JFrame
    {
    
        JButton b1;
        JLabel l1;
    
        public BackgroundImageJFrame() {
    
            setSize(400,400);
            setVisible(true);
    
            setLayout(new BorderLayout());
    
            JLabel background=new JLabel(new ImageIcon("C:\\Users\\Computer\\Downloads\\colorful_design.png"));
    
            add(background);
    
            background.setLayout(new FlowLayout());
    
            l1=new JLabel("Here is a button");
            b1=new JButton("I am a button");
    
            background.add(l1);
            background.add(b1);
        }
    
        public static void main(String args[]) 
        {
            new BackgroundImageJFrame();
        }
    }
    

    check out the below link

    http://java-demos.blogspot.in/2012/09/setting-background-image-in-jframe.html

提交回复
热议问题