-1
import java.awt.*;   

import de.javasoft.plaf.synthetica.SyntheticaClassyLookAndFeel;
import javax.swing.*;

public class TB extends JFrame  
{
    {
    try 
    { 
      UIManager.setLookAndFeel(new SyntheticaClassyLookAndFeel());
    } 
    catch (Exception e) 
    {
      e.printStackTrace();
    }}


        TB() throws ClassNotFoundException 
        { 
            frame1();

        }


    public void frame1()
    { 
                JPanel p = new JPanel();                      
                p.setLayout(new FlowLayout());               
                p.setBackground(new Color(0,0,0,100));

                JPanel p1 = new JPanel();
                p1.setBackground(new Color(0,0,0,100));


                    JLabel jl = new JLabel("");
                     setContentPane(new JLabel(new ImageIcon("src\\ New folder\\1.jpg")));
                     p1.add(jl);


                     p1.setVisible(true);
                     p1.setSize(200,150);  
                    add(p1);



                JPanel p2 = new JPanel();

                p2.setLayout(new FlowLayout());
                p2.setSize(200,100);
                p2.setBackground(new Color(0,0,0,125));

                JButton hm = new JButton ("Home");
                JButton abt = new JButton("AboutUs");
                JButton log = new JButton("SignIn");


                p2.add(hm);
                p2.add(abt);
                p2.add(log);

                add(p2);

                add(p);  
                JPanel p3 = new JPanel();
                p3.setLayout(new GridLayout(3,1,0,0));
                p3.setBackground(new Color(0,0,0,100));

                JLabel usr = new JLabel("Username   :");
                usr.setForeground(Color.white);
                JTextField usrtxt = new JTextField();
                 Component pass = new JLabel("Password  :");
                pass.setForeground(Color.white);

                JPasswordField passtxt = new JPasswordField(20);
                JButton login = new JButton("Login");
                JButton cancel = new JButton("Clear");

                p3.add(usr); 
                p3.add(usrtxt);
                p3.add(pass);
                p3.add(passtxt);
                p3.add(login);
                p3.add(cancel);
                p.add(p3);
                p3.setVisible(false);

                setTitle(" Generator 1.0");
                setLayout(new GridLayout(3,1,0,0));

                setSize(1364,700);
                setVisible(true);

                JPanel p4 = new JPanel();

                p4.setBackground(new Color(0,0,0,100));
                JLabel msg = new JLabel("About Us",JLabel.CENTER);
                msg.setForeground(Color.white);

                p4.setLayout(new GridLayout(5,1));
                p4.add(msg,JLabel.CENTER_ALIGNMENT);

                p.add(p4);
                p4.setVisible(false);

    }


    public static void main(String[]args) throws ClassNotFoundException   
            {

                TB TTV = new TB( );
                new TB();
                TTV.setDefaultCloseOperation(EXIT_ON_CLOSE);  

            }
}

enter image description here

user1803551
  • 12,965
  • 5
  • 47
  • 74
vinay negi
  • 38
  • 1
  • 7

1 Answers1

1

This new Color(0,0,0,100) isn't how you to transparency in Swing. Swing only deals with fully transparent or opaque components. In this case, specifying a alpha based color, the painting process doesn't know that it should be painting beneath the component, leading to all sorts of weird painting atrificates.

If you want transparency, then you need to fake it, but making the component completely transparent (setOpaque(false)) and overriding the component's paintComponent method and filling the component area with the translucent color you want

Something like this and this for example

Community
  • 1
  • 1
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • but why repaint() and revalidate() is not working to refresh it – vinay negi Jan 14 '16 at 05:36
  • Why should they? Each time the component is repainted, it fills it self with the background color, to clear what was previously painted to the `Graphics` context, but because you're using an alpha based color, it's not clearing it completely. – MadProgrammer Jan 14 '16 at 05:40
  • so, how can I clear it while using alpha based color? – vinay negi Jan 14 '16 at 09:32
  • You don't, you can't. You make the component transparent, you override it's `paintComponent` method (calling it's `super.paintComponent` method) and then you fill the component with your translucent color, basically faking it – MadProgrammer Jan 14 '16 at 09:40