Set Background color of JFrame

Use the following line


setContentPane(new JLabel(new ImageIcon(getClass().getResource("background.jpg"))));

For instance:

private void initComponents() {

        closeButton = new javax.swing.JButton();
        headerLabel = new javax.swing.JLabel();
        statusLabel = new javax.swing.JLabel();
      
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Background Image in JFrame");
       
setContentPane(new JLabel(new ImageIcon(getClass().getResource("background.jpg"))));
//rest of the UI initialization part

No comments:

Post a Comment