当前位置: 技术问答>java相关
怎样实现透明的panel,在线等待
来源: 互联网 发布时间:2015-11-12
本文导语: 如在上面透明panel上画线, 同时能看到下面panel上的线。 | import java.awt.*; import java.awt.event.*; import javax.swing.*; public class CSDNTest extends JFrame { public CSDNTest() { JPanel a = new JPanel(null); a.setPreferredSize(new Dim...
如在上面透明panel上画线,
同时能看到下面panel上的线。
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CSDNTest extends JFrame
{
public CSDNTest()
{
JPanel a = new JPanel(null);
a.setPreferredSize(new Dimension(300,300));
a.setBackground(Color.red);
a.setLayout(new BorderLayout());
a.add(new JLabel("This is Test."),BorderLayout.NORTH);
a.setOpaque(false);//设置JPanel为透明
Container contentPane = getContentPane();
contentPane.add(a,BorderLayout.NORTH);
setTitle("CSDN");
setBounds(0,0,600,600);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public static void main(String[] args)
{
JFrame frame = new CSDNTest();
frame.setVisible(true);
}
}
希望对你有所帮助!
import java.awt.event.*;
import javax.swing.*;
public class CSDNTest extends JFrame
{
public CSDNTest()
{
JPanel a = new JPanel(null);
a.setPreferredSize(new Dimension(300,300));
a.setBackground(Color.red);
a.setLayout(new BorderLayout());
a.add(new JLabel("This is Test."),BorderLayout.NORTH);
a.setOpaque(false);//设置JPanel为透明
Container contentPane = getContentPane();
contentPane.add(a,BorderLayout.NORTH);
setTitle("CSDN");
setBounds(0,0,600,600);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public static void main(String[] args)
{
JFrame frame = new CSDNTest();
frame.setVisible(true);
}
}
希望对你有所帮助!