为什么 SyntheticaClassyLookAndFeel 在透明面板上显示图层
why SyntheticaClassyLookAndFeel showing layer over transparent panels
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);
}
}
这 new Color(0,0,0,100)
不是您在 Swing 中实现透明度的方式。 Swing 只处理完全透明或不透明的组件。在这种情况下,指定基于 alpha 的颜色,绘画过程不知道它应该在组件下方绘画,从而导致各种奇怪的绘画错误。
如果你想要透明,那么你需要伪造它,但是让组件完全透明(setOpaque(false)
)并覆盖组件的 paintComponent
方法并用半透明颜色填充组件区域想要
例如this and
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);
}
}
这 new Color(0,0,0,100)
不是您在 Swing 中实现透明度的方式。 Swing 只处理完全透明或不透明的组件。在这种情况下,指定基于 alpha 的颜色,绘画过程不知道它应该在组件下方绘画,从而导致各种奇怪的绘画错误。
如果你想要透明,那么你需要伪造它,但是让组件完全透明(setOpaque(false)
)并覆盖组件的 paintComponent
方法并用半透明颜色填充组件区域想要
例如this and