+ 1

Drawing background in Java

Hi, guys! I’m now learning how to create pictures in Java and feeling a little confused about backgrounds. Can anyone advise me some method to fill background with a color??

11th May 2018, 7:02 PM
Novi Chok
Novi Chok - avatar
4 Antworten
+ 1
I found this at https://stackoverflow.com/questions/4219919/how-to-change-the-background-color-on-a-java-panel You could call: getContentPane().setBackground(Color.black); Or add a JPanel to the JFrame your using. Then add your components to the JPanel. This will allow you to call setBackground(Color.black); on the JPanel to set the background color
11th May 2018, 9:38 PM
Wallace Tomason
Wallace Tomason - avatar
+ 1
11th May 2018, 10:30 PM
Wallace Tomason
Wallace Tomason - avatar
0
Wallace Tomason, thank you for the answer! JPanel is already added to the JFrame, so I think setBackground will work. Actually I want to try set gradient as the background :)
11th May 2018, 9:56 PM
Novi Chok
Novi Chok - avatar
0
Ok, thank you!
11th May 2018, 11:17 PM
Novi Chok
Novi Chok - avatar