1

I'm trying to change the backgroundcolor of my Jframe & Jdialog. Adjusting the 'Background' in the GUI is not working. Any idea how I can change the background color?

Meindert Stijfhals
  • 355
  • 1
  • 3
  • 12

1 Answers1

2

you can always do this using java code, by calling the contentpane of your jframe.

try this :

myJFrame.getContentPane().setBackground(Color.YELLOW);
Alok
  • 808
  • 13
  • 40
  • Where exacly do I place it? Nvm I found it :) Thanks! – Meindert Stijfhals Jan 03 '16 at 16:09
  • you need to put it in code part of your jframe, since you are using netbeans just double click on any button or menu in your jframe or right click and go to code and put this in class constructor to initialize with jframe. – Alok Jan 03 '16 at 16:11
  • if this solved your problem , please mark it as answer – Alok Jan 03 '16 at 16:14
  • @Alok Why do we need to call `getContentPane()` first? JFrame has direct access to `setBackground()`. – Brian Jun 21 '18 at 02:06
  • @Brian if you are using content pane it will overlap jframe background, think of it as stack of elements in z-index one above another, if you dont have content pane you can change jframe background directly. we usuallly works with taking panels or content pane hence the answer – Alok Jun 21 '18 at 11:08
  • also something for your further studies on same https://stackoverflow.com/questions/16744152/java-gui-about-getcontentpane-method-and-content – Alok Jun 21 '18 at 12:56
  • @Alok Thanks! :-) – Brian Jun 21 '18 at 16:21