Reputation: 85
Im new to Swing, first of all. Im trying to set the background color of an audio recording applet to make it blend with my webpage (white instead of the default grey), but the change never seems to take. Heres the applet initialization...
public void init()
{
setLayout(null);
setBackground(Color.white);
JLabel recorder = new JLabel("Record");
JLabel fileName = new JLabel("Please Enter File Name");
JLabel status = new JLabel("Status...");
fnametxt = new JTextField("FileNameHere");
statustxt = new JTextField("");
record = new JButton("Record");
play = new JButton("Play");
pause = new JButton("Pause");
stop = new JButton("Stop");
send = new JButton("Upload");
listen = new JButton("Listen");
save = new JButton("Save and Submit");
//A bunch of other stuff, event listeners and whatnot.
Im using no layout managers, Im setting all the positions manually. Any ideas?
Upvotes: 3
Views: 5593
Reputation: 780
If you're using a JPanel in your applet, you'll have to color the JPanel's content pane as well. The following code sets the background of the JPanel itself AND its content pane to white:
setBackground(Color.white);
getContentPane().setBackground(Color.white); //Color JPanel
Upvotes: 1
Reputation: 20059
You set (presumably) the background of the Applet, but that background will only show where it is not obstructed by another component.
Depending on how you structured your GUI, there may be inner panels or other components covering the area. You need to change the color of those components, too (or alternately set them to be transparent using setOpaque(false)).
Edit: setOpaque() is only available for Swing components, not the Applet itself (since that is plain old AWT).
Upvotes: 6
Reputation: 1783
You probably should set the background color of the content pane.
Upvotes: 2