简体   繁体   English

如何使(加载)图像覆盖面板

[英]how to make an (load)image overlay a panel

In my app i have some interactive widgets but while loading data from server this widgets must be inactivated and activated again after loading is complete. 在我的应用程序中,我有一些交互式小部件,但是在从服务器加载数据时,必须禁用此小部件,并在加载完成后再次激活。 i don't want to make the widgets invisible or inactivate every single field/button. 我不想使小部件不可见或不激活每个字段/按钮。 the best solution would be a transparent panel with an loading image in its center or corner overlaying the widgets while loading - but how to achieve that? 最好的解决方案是透明面板,其中心或角落有一个加载图像,在加载时将其覆盖在小部件上,但是如何实现呢?

Here is some simple code to start with. 这是一些简单的代码。 I have used it in some application but it was with GWT 2.0, maybe they got something better now. 我曾在某些应用程序中使用过它,但GWT 2.0附带了它,也许他们现在变得更好了。 You could probably replace the Label with an animated Gif image and simply add the panel to the root panel should do the trick. 您可以用动画Gif图像替换Label,然后只需将面板添加到根面板即可。

import com.google.gwt.user.client.Event.NativePreviewEvent;
import com.google.gwt.user.client.Event.NativePreviewHandler;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.SimplePanel;

public class GlassPanel extends SimplePanel implements NativePreviewHandler {

    private Label text;

    public GlassPanel() {
        setStyleName("glass-panel");
        add(text = new Label());
    }

    public void setText(String text) {
        this.text.setText(text);
    }

    @Override
    public void onPreviewNativeEvent(NativePreviewEvent event) {
        event.consume();
        event.cancel();
    }
}

CSS: CSS:

.glass-panel {
    background-color: black;
    opacity: 0.7;
    filter: alpha(opacity=70);
    z-index: 4000;
    position: absolute;
    left: 0px;
    top: 0px;
    right: 0px;
    bottom: 0px;
}

别忘了添加“ mozOpacity”,以及“ opacity”和“ filter”(或者现在已经过时了吗?只需加上我的两分钱)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM