首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >黑色不透明的JWindow

黑色不透明的JWindow
EN

Stack Overflow用户
提问于 2010-06-19 04:11:03
回答 2查看 554关注 0票数 1

我想创建一个JWindow,它不仅具有不透明度,而且我想在Swing中更改不透明度的默认颜色。

例如,如果我写道:

代码语言:javascript
复制
AWTUtilities.setWindowOpacity(this, 0.5f);

这将做我想做的事情,但有一个例外,颜色是白色的。怎样才能让颜色变黑呢?

我在“this”上尝试了setBackground(Color.Black)等所有的东西……

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-06-19 04:20:22

代码语言:javascript
复制
        window.getContentPane().setBackground(Color.BLACK);
票数 1
EN

Stack Overflow用户

发布于 2011-12-29 00:21:10

透明JWindow。

代码语言:javascript
复制
public class TransparentWindow{

    JWindow window;

    public TransparentWindow(){
        initializeTransparentWindow();
    }

    private void initializeTransparentWindow() {
        // searching graphical configuration that provide transparent window
        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = env.getScreenDevices();
        GraphicsConfiguration translucencyCapableGC = null;
        for (int i = 0; i < devices.length && translucencyCapableGC == null; i++) {
            GraphicsConfiguration[] configs = devices[i].getConfigurations();
            for (int j = 0; j < configs.length && translucencyCapableGC == null; j++) {
                if (AWTUtilities.isTranslucencyCapable(configs[j])) {
                    translucencyCapableGC = configs[j];
                }
            }
        }
        if (translucencyCapableGC != null) {
            window = new JWindow(translucencyCapableGC) {
                @Override
                public void paint(Graphics g) {
                    if (getWidth() > 4 && getHeight() > 4) {
                        g.clearRect(0, 0, getWidth(), getHeight());
                        g.setColor(new Color(0x0, 0x0, 0x0, 0xaa));
                        g.fillRect(0, 0, 1, getHeight());
                        g.fillRect(0, 0, getWidth(), 1);
                        g.fillRect(0, getHeight() - 1, getWidth(), 1);
                        g.fillRect(getWidth() - 1, 0, 1, getHeight());
                        g.setColor(new Color(0x0, 0x0, 0x0, 0x10));
                        g.fillRect(1, 1, getWidth() - 1, getHeight() - 1);
                    }
                };
            };
            AWTUtilities.setWindowOpaque(window, false);
        }
        else {
            window = new JWindow();
            AWTUtilities.setWindowOpacity(window, 0.5f);
        }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3072756

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档