jdk7透明异形窗体_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > jdk7透明异形窗体

jdk7透明异形窗体

 2014/4/10 21:45:11  alanland  程序员俱乐部  我要评论(0)
  • 摘要:在jdk6中设置透明异形窗体的方法与jdk7方法的比较MethodinJavaSE6Update10JDK7EquivalentAWTUtilities.isTranslucencySupported(Translucency)GraphicsDevice.isWindowTranslucencySupported(WindowTranslucency)AWTUtilities.isTranslucencyCapable(GraphicsConfiguration
  • 标签:jdk

在jdk6中设置透明异形窗体的方法与jdk7方法的比较

Method in Java SE 6 Update 10 JDK 7 Equivalent AWTUtilities.isTranslucencySupported(Translucency) GraphicsDevice.isWindowTranslucencySupported(WindowTranslucency) AWTUtilities.isTranslucencyCapable(GraphicsConfiguration) GraphicsConfiguration.isTranslucencyCapable() AWTUtilities.setWindowOpacity(Window, float) Window.setOpacity(float) AWTUtilities.setWindowShape(Window, Shape) Window.setShape(Shape) AWTUtilities.setWindowOpaque(boolean) Window.setBackground(Color) Passing new Color(0,0,0,alpha) to this method, wherealpha is less than 255, installs per-pixel translucency.

monospace; white-space: pre; font-size: 16px;">jdk7判断操作系统是否支持透明窗体的设置

[html] view plaincopy
    class="dp-xml">
  1. //?Determine?what?the?default?GraphicsDevice?can?support.??
  2. ????????GraphicsEnvironment?ge?=?GraphicsEnvironment??
  3. ????????????????.getLocalGraphicsEnvironment();??
  4. ????????GraphicsDevice?gd?=?ge.getDefaultScreenDevice();??
  5. ??
  6. ????????boolean?isUniformTranslucencySupported?=?gd??
  7. ????????????????.isWindowTranslucencySupported(TRANSLUCENT);//是否支持全部统一透明度的窗体??
  8. ??????????
  9. ????????boolean?isPerPixelTranslucencySupported?=?gd??
  10. ????????????????.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT);//是否每部分不同透明度的窗体??
  11. ??????????
  12. ????????boolean?isShapedWindowSupported?=?gd??
  13. ????????????????.isWindowTranslucencySupported(PERPIXEL_TRANSPARENT);//是否支持异性窗体??
  14. ??????????
  15. ????????System.out.println("isUniformTranslucencySupported:"+isUniformTranslucencySupported);??
  16. ????????System.out.println("isPerPixelTranslucencySupported:"+isPerPixelTranslucencySupported);??
  17. ????????System.out.println("isShapedWindowSupported:"+isShapedWindowSupported);??

?

1.统一透明度窗体的设置

[html] view plaincopy
  1. GraphicsEnvironment?ge?=?GraphicsEnvironment??
  2. ????????????????.getLocalGraphicsEnvironment();??
  3. ????????GraphicsDevice?gd?=?ge.getDefaultScreenDevice();??
  4. ??
  5. ????????boolean?isUniformTranslucencySupported?=?gd??
  6. ????????????????.isWindowTranslucencySupported(TRANSLUCENT);//是否支持全部统一透明度的窗体??
  7. ????????if(isUniformTranslucencySupported)??
  8. ????????{??
  9. ????????????JFrame.setDefaultLookAndFeelDecorated(true);??
  10. ????????????JFrame?jf=new?JFrame("统一透明度");??
  11. ????????????jf.setLayout(new?GridBagLayout());??
  12. ????????????Button?bu=new?Button("这是个按钮");??
  13. ????????????jf.add(bu);??
  14. ????????????jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);??
  15. ????????????jf.setBounds(100,?60,?200,?300);??
  16. ????????????jf.setOpacity(0.8f);??
  17. ????????????jf.setVisible(true);??
  18. ????????}??

?

刚开始一直弄官方例子http://download.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html,发现一直报错

[html] view plaincopy
  1. Exception?in?thread?"AWT-EventQueue-0"?java.awt.IllegalComponentStateException:?The?frame?is?decorated??
  2. ????at?java.awt.Frame.setOpacity(Unknown?Source)??


原来setOpacity方法说明

[html] view plaincopy
  1. The?TRANSLUCENT?translucency?must?be?supported?by?the?underlying?system??
  2. The?window?must?be?undecorated?(see?setUndecorated(boolean)?and?Dialog.setUndecorated(boolean))??
  3. The?window?must?not?be?in?full-screen?mode?(see?GraphicsDevice.setFullScreenWindow(Window))??


1.操作系统必须支持设置透明方法
2.窗体必须未修饰(无标题栏)
3.窗体必须非全屏模式

加上一句

[html] view plaincopy
  1. JFrame.setDefaultLookAndFeelDecorated(true);?
发表评论
用户名: 匿名