0

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

camickr
  • 321,443
  • 19
  • 166
  • 288
Namita Geo.
  • 1
  • 1
  • 5
  • 1
    Im not exactly understanding for which part of your jdesktoppane you want to change the color – Donatic Aug 24 '18 at 07:19
  • `I have tried changing the colour of the desktop pane` - where? Your code should be something like: `JDesktopPane desktop = new JDesktop(); desktop.setBackground( Color.RED );` First get this working, then if you want to make it more dynamic use the JColorChooser. If you have problems then pPost your [mcve] that demonstrates the problem because we can't guess what you are doing. Don't use the IDE to change the color. Learn how to write your own code to set properties of components so you learn Swing, not the IDE. – camickr Aug 24 '18 at 13:59
  • @Donatic I'm kinda new to java so I'm trying not to use codes. the part I'm trying to change is the LIGHT BLUE COLOUR u can see in the pic. I want to set it to the purple colour I have used in the panel. – Namita Geo. Aug 26 '18 at 08:44
  • @camirk I am kinda new to java.. so I know only the basic codes. I need to submit it by 28th so I'm trying not to use too much codes. "I have tried changing the colour of the desktop pane" - I meant that I tried through the properties as shown above. And how else am I supposed to show you the colour I'm choosing is not coming? – Namita Geo. Aug 26 '18 at 08:49

1 Answers1

0

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();
        }
};
blueflamer
  • 44
  • 3
  • ,I have no idea what nimbus or L&F is. I'm using Java Netbeans 8.2. And can you tell me how to change background colour without any coding? (like through its properties.) – Namita Geo. Aug 26 '18 at 08:52