为什么SyntheticaClassyLookAndFeel在透明面板上显示图层

时间:2016-01-13 19:02:41

标签: java swing look-and-feel

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

1 个答案:

答案 0 :(得分:1)

这个new Color(0,0,0,100)并不是你如何在Swing中透明化。 Swing仅处理完全透明或不透明的组件。在这种情况下,指定基于alpha的颜色,绘画过程不知道它应该在组件下面绘画,导致各种奇怪的绘画atrificates。

如果你想要透明度,那么你需要假装它,但是让组件完全透明(setOpaque(false))并覆盖组件的paintComponent方法并用半透明填充组件区域你想要的颜色

例如thisthis之类的内容