如何设置JDialog的透明背景
嘿,..
我如何设置背景透明并“删除”关闭操作(标记为红色)? 我只想出示卡片:-)
谢谢..!
Hy,..
how can i set the background transparent and "remove" the closeoperation (marked red) ?
I only want to show the card :-)
Thanks..!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
虽然 UNDECORATED JFrame 透明度没有问题(myJFrame.setBackground (new Color (0,0,0,0)); 已经足够漂亮了),但与 JDialog 一样不起作用。
然而,我发现以下序列对于 JDialog 来说是完美的:
A 也保留,但这是我私人的、谦虚的建议,所有对 Window 扩展器(例如 JFrame、JDialog)的 setBackground 调用都应该针对 UnsupportedOperationException 和 IllegalComponentStateException 进行尝试。
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:
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.
yourDialog.setUndecorated(true)
应该可以解决标题栏的问题。用于使框架透明。您必须在根面板上使用
yourDialog.getRootPane().setOpaque(false)
进行操作。yourDialog.setUndecorated(true)
should do the trick for the title bar.For having the Frame transparent. You'll have to work on the root panel with
yourDialog.getRootPane().setOpaque(false)
on it.我按照文章中的说明进行操作,最终成功了,而且一点也不困难。 :)
我现在有了半透明的 SplashImage 和 About 屏幕,它显示 PNG 图像并尊重其(复杂的)透明度。太棒了。
请注意,在 JDK 7 中,继续操作的方法会略有变化。
只需注意关键字之间的差异即可。
http://download.oracle.com/javase/tutorial/uiswing /misc/trans_shape_windows.html#6u10
如果这个技巧能奏效那就太好了
,但对我来说却没有。也许我做错了什么。
我还注意到使用 setContentPane(Component); 很重要而不是 getContentPane.add(Component);
我很高兴它现在可以工作了! :)
I followed the instructions from the article and it worked finnaly AND it wasn't difficult at all. :)
I now have my translucent SplashImage ans About screen which displays a PNG image and respect its (complex) transparency. Just awesome.
Note that the method to proceed will change a little bit in JDK 7.
Just notice the difference between keywords.
http://download.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html#6u10
It would have been nice if the
trick worked but it didn't to me. Maybe I did something wrong.
I also note it is important to use setContentPane(Component); instead of getContentPane.add(Component);
I'm happy it works now ! :)