Make a JPanel not draw its background (Transparent)

后端 未结 5 1204
孤城傲影
孤城傲影 2020-12-05 17:50

Is it possible, in Java, to make a JPanel skip drawing its background thus being transparent except for the components on it?

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 18:24

    class TransparentJPanel extends JPanel
    {
        TransparentJPanel()
        {
            super() ;
            this.setOpaque( false ) ; // this will make the JPanel transparent 
                                      // but not its components (JLabel, TextField etc.)
            this.setLayout( null ) ;
        }
    }
    

提交回复
热议问题