簡體   English   中英

如何使用分層窗格?

[英]How do I use layered pane?

我想要一個背景圖片,在它上面,我想要一個供用戶單擊並執行操作的圖像。

如何正確使用?

b.addActionListener(new ActionListener() {          
        @Override
        public void actionPerformed(ActionEvent e) {
            p.setVisible(false);
            p2.setVisible(false);
            JLayeredPane lp2=new JLayeredPane();
            JLayeredPane lp=new JLayeredPane();
            ImageIcon image=new ImageIcon(getClass().getResource("800x800.jpg"));
            JLabel lbl=new JLabel(image);
            ImageIcon image2=new ImageIcon(getClass().getResource("imageYEA.jpg"));
            JLabel lbl2=new JLabel(image2);
            lp2.add(lbl2);
            lp.add(lbl);
            add(lp2);
            add(lp);
        }
    });

首先,我認為您不需要2個分層的窗格。 您制作一張,然后在該窗格上繪制2張圖片。 它們以預定義的偏移重疊。 您可以在以下官方Oracle教程中看到它的完成方式: LayeredPaneDemo.java 如果您想用上面的圖片做點什么,我想普通的事件處理程序將為您完成這項工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM