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?
Asked
Active
Viewed 3,284 times
1
-
Asked and answered here *many* times. In the future, please search on your problem first to see if it is unique. – Hovercraft Full Of Eels Jan 03 '16 at 17:26
1 Answers
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
-
-
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
-
-
@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
-