2011-11-07 175 views
1

第一次绘制时,绘制不正确。 但是,当我最小化框架并恢复它时,它被正确绘制。重新绘制Aero JFrame

我该如何解决这个问题?我试图重绘()。

下面是代码

import javax.swing.JComponent; 
import javax.swing.JFrame; 

import com.sun.jna.Function; 
import com.sun.jna.Native; 
import com.sun.jna.NativeLibrary; 
import com.sun.jna.Structure; 
import com.sun.jna.platform.win32.WinDef.HWND; 
import com.sun.jna.platform.win32.WinNT.HRESULT; 

/** 
* @author ex0b1t 
* 
*/ 
public class Aero { 

    public void enableAeroEffect(JFrame frame) {   

     NativeLibrary dwmapi = NativeLibrary.getInstance("dwmapi"); 
     HWND aeroFrameHWND = new HWND(Native.getWindowPointer(frame)); 

     MARGINS margins = new MARGINS(); 
     margins.cxLeftWidth = -1; 
     margins.cxRightWidth = -1; 
     margins.cyBottomHeight = -1; 
     margins.cyTopHeight = -1; 

     Function extendFrameIntoClientArea = dwmapi 
       .getFunction("DwmExtendFrameIntoClientArea"); 
     HRESULT result = (HRESULT) extendFrameIntoClientArea.invoke(
       HRESULT.class, new Object[] { aeroFrameHWND, margins }); 
     if (result.intValue() != 0) 
      System.err.println("Call to DwmExtendFrameIntoClientArea failed."); 

     frame.getRootPane().setDoubleBuffered(false); 
     frame.getRootPane().setOpaque(false); 

     if (frame.getRootPane().getContentPane() instanceof JComponent) { 
      JComponent content = (JComponent) frame.getRootPane().getContentPane(); 
      content.setOpaque(false); 
      content.setDoubleBuffered(false); 
     }  
    } 

    /** 
    * @author ex0b1t 
    * 
    */ 
    public class MARGINS extends Structure implements Structure.ByReference { 
     public int cxLeftWidth; 
     public int cxRightWidth; 
     public int cyTopHeight; 
     public int cyBottomHeight; 
    } 
} 



import javax.swing.JFrame; 

/** 
* @author ex0b1t 
* 
*/ 

public class MediaManager extends JFrame { 

    private static final long serialVersionUID = -8440221168382362270L; 

    public MediaManager() {  
     setTitle("Media Manager"); 
     setSize(800, 600); 
     setDefaultCloseOperation(EXIT_ON_CLOSE); 
    } 

    /** 
    * @param args 
    */ 
    public static void main(String[]args){ 
     MediaManager mediamanager = new MediaManager(); 
     mediamanager.setVisible(true); 
     new Aero().enableAeroEffect(mediamanager); 
     mediamanager.repaint(); 
    } 
} 

预先感谢。

回答

1

设置框架的扩展状态图标化和恢复正常的意志画框架correctley。然而,当我添加一个组件到框架的背景是regrawn incorectley。

frame.setExtendedState(JFrame.ICONIFIED); 
frame.setExtendedState(JFrame.NORMAL); 
1

当你说它没有被正确涂漆时,你是什么意思? 我有一个类似的问题,当我的框架第一次绘制时,contentPane完全是黑色的。当我最小化框架,然后使其最大化时,它被正确绘制(但并不总是 - 有时我不得不做它2或3次)。原来它是我的显卡的驱动程序。我重新安装了它们,它工作正常! (我有一个Randeon)

也尽量

  SwingUtilities.invokeLater(new Runnable(){ 
        @Override 
        public void run(){ 
         mediamanager.setVisible(true); 
         new Aero().enableAeroEffect(mediamanager); 
         mediamanager.repaint(); 
        } 
      } 

线程和Swing

http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html

SwingUtilities.invokeLater

+0

http://dl.dropbox.com/u/21666209/1.PNG示出了初始载荷 – ex0b1t

+0

http://dl.dropbox.com/u/21666209/2.PNG显示图像恢复后 – ex0b1t