如何使渐进的背景图像的AWT组件透明?二手窗口(),面板(),巴顿(),但失败 [英] How to make the AWT component transparent on progressive background image? Used Window(), Panel(), Button() but failed

查看:187
本文介绍了如何使渐进的背景图像的AWT组件透明?二手窗口(),面板(),巴顿(),但失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能让AWT组件透明时,背景是逐行扫描图像?

How can i make AWT component transparent when the background is progressive image?

请注意:只使用,其中渐进式窗口()5帧/每秒AWT。面板(),而使用新的颜色(255,0,0,0)是不是现在越来越透明。如何使面板透明?

Note: AWT used only, where progressive Window() 5 frames/per second. Panel() is not getting transparent now while using new Color(255,0,0,0). How to make the panel transparent?

AWT?这里:

public class 888 extends Window 
{
    private Button button;

    public 888() 
    {
        super(new Frame());
        // Transparent failed
        getOwner().setBackground(new Color(255, 0, 0, 0) );

        this.setLayout (new BorderLayout ());

        button = new Button("close");

        button.setBackground(Color.RED);
        button.setSize(200,200);
        button.setLocation(0,20);

        this.add("North", button);

        Panel p = new Panel();
        //p.setOpaque(false);
        p.setSize(200,200);
        p.setLocation(400,400);
        // Transparent failed
        p.setBackground(new Color(255,0,0,0));
        p.add("Left", new Button("Test"));
        this.add("North", p);

        //AWTUtilities.setWindowOpacity(this, 0.2f); // Error in Linux

    }


    public static void main(String[] args) 
    {
        Window j = new 888();
        j.setVisible(true);
        //j.setBackground( new Color(255, 0, 0, 0) );
    }

}

?:秋千这里

public class 888 extends JWindow 
{
    private JButton button;

    public 888() 
    {
        //super(new Frame());
    // Transparent failed
        getOwner().setBackground(new Color(255, 0, 0, 0) ); 

        this.setLayout (new BorderLayout ());

        button = new JButton("close");

        button.setBackground(new Color(255,0,0,255));
        button.setSize(200,200);
        button.setLocation(0,20);

        this.add("North", button);

        JPanel p = new JPanel();
        //p.setOpaque(false);
        p.setSize(200,200);
        p.setLocation(400,400);
        // Transparent failed
        p.setBackground(new Color(255,0,0,0));
        p.add("Left", new Button("Test"));
        this.add("North", p);

        //AWTUtilities.setWindowOpacity(this, 0.2f); // Error in Linux

    }


    public static void main(String[] args) 
    {
        JWindow j = new 888();
        j.setVisible(true);
        //j.setBackground( new Color(255, 0, 0, 0) );
    }

}

注:没有真正的作品,与Swing我有问题的JButton,因为当得到的JWindow刷新的JButton不可见。与AWT当我使用按钮和面板,然后没有任何可以设置透明度。

Note: None really works, with Swing i have problem with JButton, because when the JWindow get refreshed the JButton become invisible. With AWT when i use Button and Panel then none can set its transparency.

如何解决这个问题呢?对于渐进式的背景图像面板或按钮,使透明?

How do i solve it? For progressive background image Panel or Button to make transparent?

摘要:

我来到了一个点现在在做很多测试,这是不是其他任何地方了。大多是在逐行扫描窗口()或的JWindow()。你最好使用AWT的(无透明物体),以及用于摆动(透明物体)。不要像很多结论不使用AWT和Swing,你必须要聪明无尽的夏天69混了,否则会结束了:)

I came to a point now after doing many tests, which is not available anywhere else. Mostly in a progressive scan Window() or JWindow(). You better use Awt for (no transparent objects), and Swing for (transparent objects). Do not make a conclusion like many not to use Awt and Swing, you have to be smart to mix it, else gonna end up with endless summer of 69 :)

参考:

http://java.sun.com/docs/书籍/教程/ uiswing /并发/ index.html的
http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html
http://java.sun.com/products/jfc/tsc /articles/threads/threads3.html

推荐答案

这是你对这个话题的第二个问题,我还不能告诉你在做什么。你一直谈论的背景图像,但在你的code无你在哪里展示code的形象。

This is your second question on this topic and I still can't tell what you are doing. You keep talking about a background image, but no where in your code do you show the code for the image.

是有当您使用的setColor与0的alpha值你应该这样做的问题。正确的解决方法就是使组件非不透明。

Yes there are problems when you use setColor with an alpha value of 0. You should NOT do this. The proper solution is to just make the component non-opaque.

请参阅背景随着透明度的更多信息。

或许背景面板是你正在寻找。

另外你限制的使用是旧的:

Also you usage of constraints is old:

this.add("North", button); 

首先,你应该不难code的约束值。其次,如果你读theAPI你会看到,你应该使用:

First of all you should not hard code the constraint value. Secondly if you read theAPI you will see that you should be using:

this.add(button, BorderLayout.NORTH); 

和使用布局管理器,当你不设置大小和位置。

and when using layout managers you don't set the size and location.

这篇关于如何使渐进的背景图像的AWT组件透明?二手窗口(),面板(),巴顿(),但失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆