第一次画的时候,它画得不正确。但是,当我最小化框架并恢复它时,它是正确绘制的。
我该如何解决这个问题呢?我尝试过repaint()。
以下是代码
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();
}
}提前感谢。
发布于 2011-11-08 14:19:35
将框架的扩展状态设置为“图标化”并恢复为“正常”将正确绘制框架。然而,当我添加一个组件到框架中时,背景被重新抓取到incorectley中。
frame.setExtendedState(JFrame.ICONIFIED);
frame.setExtendedState(JFrame.NORMAL);发布于 2011-11-07 22:23:28
你说画得不对是什么意思?我遇到了一个类似的问题,当我的框架第一次被绘制时,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
https://stackoverflow.com/questions/8037609
复制相似问题