重新绘制 Aero JFrame

发布于 2024-12-14 08:29:43 字数 2439 浏览 0 评论 0原文

第一次涂漆时,涂漆不正确。 然而,当我最小化框架并恢复它时,它被正确绘制。

我将如何解决这个问题?我尝试过重新绘制()。

这是代码,

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();
    }
}

提前致谢。

That when painted for the first time, it is not painted correctly.
However, when I minimize the frame and restore it, it is painted correctly.

How will I fix this? I have tried repaint().

Here is the code

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();
    }
}

Thank in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不奢求什么 2024-12-21 08:29:43

当你说它没有正确绘制时,你是什么意思?
我遇到了类似的问题,当我的框架第一次被绘制时,contentPane 是全黑的。当我最小化框架然后最大化它时,它被正确地绘制了(但并非总是如此 - 有时我必须这样做 2 或 3 次。)事实证明这是我的显卡驱动程序。我重新安装了它们,效果很好! (我有 Randeon)

也尝试

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

Threads 和 Swing

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

SwingUtilities.invokeLater

What do you mean when you say it is not correctly painted?
I had a similar problem where when my frame was painted for the first time the contentPane was totally black. When i minimized the frame and then maximizing it,it was painted correctly (but not always- there were times i had to do it 2 or 3 times.) It turned out it was the drivers of my graphics card. I reinstalled them and it worked fine! (I had a Randeon)

also try

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

Threads and Swing

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

SwingUtilities.invokeLater

无名指的心愿 2024-12-21 08:29:43

将框架的扩展状态设置为图标化并恢复正常将正确绘制框架。但是,当我向框架添加组件时,背景会不正确地重新生成。

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

setting the extended state of the frame to iconified and back to normal will paint the frame correctley. however when i add a component to the frame the backround is regrawn incorectley.

frame.setExtendedState(JFrame.ICONIFIED);
frame.setExtendedState(JFrame.NORMAL);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文