Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Swing Applet- Cant set background color

Tags:

java

applet

swing

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?

like image 674
Woobie Avatar asked Jul 31 '26 19:07

Woobie


2 Answers

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).

like image 56
Durandal Avatar answered Aug 02 '26 07:08

Durandal


You probably should set the background color of the content pane.

like image 42
martijno Avatar answered Aug 02 '26 08:08

martijno



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!