繁体   English   中英

具有透明背景的未修饰JFrame?

[英]Undecorated JFrame with transparent background?

有没有办法制作带有透明背景的未经装饰的JFrame? 我想制作一个GUI,用LeapMotion设备控制Lego Mindstorm机器人。 现在,我需要一个弹出窗口,以获取一些用户反馈和选项菜单。

这是我的弹出式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);

}

我认为此链接将为您服务。

Java中未装饰的半透明形状的窗口

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM