How to set transparent background of JDialog

前端 未结 3 1515
南笙
南笙 2021-01-11 17:43

Hy,..

how can i set the background transparent and \"remove\" the closeoperation (marked red) ? I only want to show the card :-)

3条回答
  •  迷失自我
    2021-01-11 18:43

    Although there is no problem with UNDECORATED JFrame transparency (myJFrame.setBackground (new Color (0,0,0,0)); is pretty enough), the same with JDialog is not working.

    I discovered, however, the following sequence works perfect for JDialog:

    myJDialog.getRootPane ().setOpaque (false);
    myJDialog.getContentPane ().setBackground (new Color (0, 0, 0, 0));
    myJDialog.setBackground (new Color (0, 0, 0, 0));
    

    A also remain, but it is my PRIVATE, humble suggestion, that all setBackground call for Window extenders (e.g. JFrame, JDialog) should be tried against UnsupportedOperationException and IllegalComponentStateException.

提交回复
热议问题