簡體   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