The window background color refers to the color displayed after directly calling the setBackground(Color color) method of JFrame or Frame.
If you call this method directly, the background color is indeed set, but what you see is not the direct JFrame or Frame, but JFrame.getContentPane(), and the contentPane on the JFrame defaults to Color.WHITE . So, no matter how you set the background color for JFrame or Frame, all you see is the contentPane.
Recommended related video tutorials: java video tutorials
Solution:
Method 1: After completing the initialization, call getContentPane () method gets a contentPane container, and then sets it to invisible, that is, setVisible(false).
The code is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Method 2: Directly add this.getContentPane().setBackground(Color.blue);
The code is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Recommended related articles and tutorials: java introductory tutorial
The above is the detailed content of java window background color setting. For more information, please follow other related articles on the PHP Chinese website!