Make a JPanel not draw its background (Transparent)

后端 未结 5 1194
孤城傲影
孤城傲影 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

    This article seems to have some handy info on how to create shaped and transparent windows in Java:

    https://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html

    0 讨论(0)
  • 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 ) ;
        }
    }
    
    0 讨论(0)
  • 2020-12-05 18:26

    Technically a JPanel may start off non-opague. This was true for the Gtk look & feel in 1.5 (or 1.4?), but no other PL&Fs as far as I am aware.

    0 讨论(0)
  • 2020-12-05 18:27

    If you are using NetBeans, Then Do these steps:-

    1. Right Click on JPanel.
    2. Scroll Down and Search For (( Opaque )). It must be there.
    3. Uncheck it.
    4. Now your JPanel background will be removed and what will appear in JPanel Background is your Background of JFrame.
    0 讨论(0)
  • 2020-12-05 18:29

    setOpaque(false)

    It'll pass off painting the background to its parent, which may draw its own background.

    You can do a screen capture and then use that to paint the background of the panel.

    0 讨论(0)
提交回复
热议问题