问题描述
在Java1.5中如何设置jwindow透明,查了下其他有说用AWTUtilities.setWindowOpacity(frame,0.5f);但这个是在JDK1.6中的,是否可以把1.6的这个包importcom.sun.awt.AWTUtilities导入到1.5??还是有其他的方法??请给点实例哈。。谢谢;
解决方案
解决方案二:
你把你的jre环境设置成1.6的不行么
解决方案三:
不然你只能重写jwindow了:classMyWindowextendsJWindow{/**thescreenshotthatisusedtodrawtransparency*/protectedBufferedImagescreenShot=null;/**therobotinstancethatcapturesscreenshots*/protectedRobotrobot;/**therectanglethatdefinesthescreendimensions*/protectedRectanglerect;publicMyWindow(JFrameframe){super(frame);try{robot=newRobot();}catch(AWTExceptione){e.printStackTrace();}}/*(non-Javadoc)*@seejava.awt.Component#paint(java.awt.Graphics)*/publicvoidpaint(Graphicsg){if(robot!=null){Graphics2Dg2D=(Graphics2D)g;g2D.drawImage(screenShot,null,0,0);g2D.setColor(Color.RED);g2D.drawLine(rect.x,rect.y,rect.x+rect.width,rect.y+rect.height);}}/***Setstheframevisibilityandalso,iftransparencyisturnedon,captures*thescreenshot.*@paramisVisiblethevisibilityoftheframe*/publicvoidsetVisible(booleanisVisible){if(isVisible){captureScreenShot();}super.setVisible(isVisible);}privatevoidcaptureScreenShot(){try{robot=newRobot();rect=getBounds();screenShot=robot.createScreenCapture(rect);}catch(java.awt.AWTExceptionex){}}}
解决方案四:
使用jna。下载jna.jar+platform.jar使用WindowUtils的setWindowAlpha方法