How to change colour of jDesktopPane from properties

574 Views Asked by At

I am creating a project that requires the use of multiple internal frames and interconnecting it through the desktop pane.

I have tried changing the colour of the desktop pane (from the property->background)but when I run it it's still that default Blue colour.

Check attached snapshot link maybe you will better understand my question what I want.

FRAME BLUE COLOUR:

https://i.stack.imgur.com/IzTNj.png

PROPERTY SET COLOUR:

https://i.stack.imgur.com/dVhoT.png

1

There are 1 best solutions below

1
blueflamer On

It appears that you're using Nimbus L&F? Background color of JDesktopPane and other components are handled by the L&F. You can override the background as such:

desktop = new JDesktopPane() {

        @Override
        public void updateUI() {
            if ("Nimbus".equals(UIManager.getLookAndFeel().getName())) {
                UIDefaults map = new UIDefaults();
                Painter<JComponent> painter = new Painter<JComponent>() {

                    @Override
                    public void paint(Graphics2D g, JComponent c, int w,
                            int h) {
                        g.setColor(Color.white); //background color
                        g.fillRect(0, 0, w, h);
                    }
                };
                map.put("DesktopPane[Enabled].backgroundPainter", painter);
                putClientProperty("Nimbus.Overrides", map);
            }
            super.updateUI();
        }
};