有没有办法制作一个透明背景的未修饰的JFrame?我想制作一个用LeapMotion设备控制Lego Mindstorm机器人的GUI。现在我需要一个弹出窗口来显示一些用户反馈和选项菜单。
这是我的弹出式JFrame类的代码
public Sub_PopUp(int width, int height)
{
this.width = width;
this.height = height;
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new BorderLayout());
this.setBounds(300, 300, this.width, this.height);
this.setResizable(false);
this.setUndecorated(true);
this.setVisible(true);
this.setOpacity(0.9f);
contentPane = new JPanel();
this.setContentPane(contentPane);
contentPane.setLayout(null);
contentPane.setBounds(0, 0, this.width, this.height);
contentPane.setOpaque(false);
try
{
imgLtb = ImageIO.read(new File("img/popup_ltb.png"));
imgTb = ImageIO.read(new File("img/popup_tb.png"));
imgRtb = ImageIO.read(new File("img/popup_rtb.png"));
imgRb = ImageIO.read(new File("img/popup_rb.png"));
imgRbb = ImageIO.read(new File("img/popup_rbb.png"));
imgBb = ImageIO.read(new File("img/popup_bb.png"));
imgLbb = ImageIO.read(new File("img/popup_lbb.png"));
imgLb = ImageIO.read(new File("img/popup_lb.png"));
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
ltb = new Sub_BackgroundPanel(imgLtb);
ltb.setOpaque(false);
ltb.setBounds(0, 0, 35, 35);
tb = new Sub_BackgroundPanel(imgTb);
tb.setBounds(35, 0, width-70, 35);
rtb = new Sub_BackgroundPanel(imgRtb);
rtb.setBounds(width-35, 0, 35, 35);
rb = new Sub_BackgroundPanel(imgRb);
rb.setBounds(width-35, 35, 35, height-70);
rbb = new Sub_BackgroundPanel(imgRbb);
rbb.setBounds(width-35, height-35, 35, 35);
bb = new Sub_BackgroundPanel(imgBb);
bb.setBounds(35, height-35, width-70, 35);
lbb = new Sub_BackgroundPanel(imgLbb);
lbb.setBounds(0, height-35, 35, 35);
lb = new Sub_BackgroundPanel(imgLb);
lb.setBounds(0, 35, 35, height-70);
middle = new JPanel();
middle.setBounds(35, 35, width-70, height-70);
middle.setBackground(Color.decode("#9db4bd"));
contentPane.add(middle);
contentPane.add(ltb);
contentPane.add(tb);
contentPane.add(rtb);
contentPane.add(rb);
contentPane.add(rbb);
contentPane.add(bb);
contentPane.add(lbb);
contentPane.add(lb);
}