Aiman Muzafar Aiman Muzafar - 1 year ago 103
Java Question

Netbeans making a JTextField transparent not working

I've put a background image on a JFrame by putting it as an icon of JLabel. But the problem is my textfield and password fields are not getting transparent. I've disable the opaque in the the properties of both fields. It looks transparent inside the preview of netbeans like this

It has also generated the code

But still when I run the instance of the code, the fields have their own white background.

Any help is appreciated. Thanks.

Answer Source

The problem is the background color and the color chooser of the jtextfield. It resets the transparent component of the color.

Solution: Don't use the color chooser. Use the option "Custom code". Then set the color to

new java.awt.Color(255, 255, 255, 0)

(opaque can still be active)

Your initComponents should look like this...

private void initComponents() {

    jPanel1 = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    jTextField1 = new javax.swing.JTextField();

    setBackground(new java.awt.Color(255, 255, 0));

    jPanel1.setBackground(new java.awt.Color(255, 51, 51));


    jTextField1.setBackground(new java.awt.Color(255, 255, 255, 0));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download