javamacosswingjdesktoppane

JFrame suddenly contain blue background


I am trying to create a simple program using JInternalFrame on Swing and when i run my code, it suddenly produces a blue background. Can anyone tell me how i can remove it? here is the code i tried

import javax.swing.*;

public class Main extends JFrame {

    JDesktopPane dp = new JDesktopPane();
    JInternalFrame intf = new JInternalFrame("demo");

    public void initialize() {
        setTitle("Test Program");
        setSize(500, 500);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);
    }

    public Main() {
        intf.setSize(150, 200);
        intf.setVisible(true);
        dp.add(intf);
        add(dp);
        initialize();
    }

    public static void main(String args[]) {
        new Main();
    }

}

here is the result shown after i run my code


Solution

  • It's part of the PL&F.

    To literally remove it you can make the JDesktopPane non-opaque:

    dp.setOpaque(false);
    

    Or set the background to a colour that you like:

    dp.setBackground(new java.awt.Color(200,200,200));
    

    But it looks weird with a light colour.

    There's probably someway of configuring the macOS PL&F. All just live with macOS looking like macOS wants to look.