GWT 选项卡面板关闭

发布于 2024-11-09 02:07:11 字数 120 浏览 0 评论 0原文

我正在 GWT 中构建一个应用程序。我有一个装饰过的标签面板 我的应用程序。在哪里动态添加面板。现在我想要 来实现这些选项卡的关闭。我想添加一张近距离图像 将选项卡栏和事件添加到该图像以进行关闭。我正在使用 UIbinder。

I am building an application in GWT. I have a decorated tabpanel in
my application.Where in am adding panels to it dynamically.Now i want
to achieve the closing of these tabs. I want to add a close image to
the tab bar and event to that image for closing. I am using UIbinder.

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

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

发布评论

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

评论(3

梦情居士 2024-11-16 02:07:30

您有点需要按照此

标题中的 GWT 关闭按钮 做一些事情DialogBox 的 bar

首先,创建新选项卡时需要传入选项卡标题。您传入的标头应包含选项卡文本以及可供单击的 X 图像或文本标签。然后在 close 对象上添加一个事件处理程序,该事件处理程序获取要添加到 tabPanel 的小部件并将其删除。这是一些有效的内联代码

public void loadTab(final Widget widget, String headingText, String tooltip) {

        HorizontalPanel panel = new HorizontalPanel();
        panel.setStyleName("tabHeader");
        panel.setTitle(tooltip);
        Label text = new Label();
        text.setText(headingText);
        text.setStyleDependentName("text", true);
        Label close = new Label();
        close.setText("X");
        close.setTitle(closeText_ + headingText);
        text.setStyleDependentName("close", true);
        close.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                Window.alert("close this tab");
                ClientGlobal.LOG.info("widget : " + tabPanel_.getWidgetIndex(widget));
                tabPanel_.remove(tabPanel_.getWidgetIndex(widget));
            }
        });
        panel.add(text);
        panel.add(close);
        panel.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_LEFT);
        panel.setCellHorizontalAlignment(close, HasHorizontalAlignment.ALIGN_RIGHT);

        tabPanel_.add(widget, panel);
        tabPanel_.getTabWidget(widget).setTitle(tooltip);
        tabPanel_.selectTab(widget);
    }

You kinda need to do something along the lines of this

GWT Close button in title bar of DialogBox

First you need to pass in the tab header when you create the new tab. The header you pass in should have your tab text and also an X image or text label to click on. Then add a event handler on the close object that gets the widget you are adding to the tabPanel and removes it. Here is some inline code that works

public void loadTab(final Widget widget, String headingText, String tooltip) {

        HorizontalPanel panel = new HorizontalPanel();
        panel.setStyleName("tabHeader");
        panel.setTitle(tooltip);
        Label text = new Label();
        text.setText(headingText);
        text.setStyleDependentName("text", true);
        Label close = new Label();
        close.setText("X");
        close.setTitle(closeText_ + headingText);
        text.setStyleDependentName("close", true);
        close.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                Window.alert("close this tab");
                ClientGlobal.LOG.info("widget : " + tabPanel_.getWidgetIndex(widget));
                tabPanel_.remove(tabPanel_.getWidgetIndex(widget));
            }
        });
        panel.add(text);
        panel.add(close);
        panel.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_LEFT);
        panel.setCellHorizontalAlignment(close, HasHorizontalAlignment.ALIGN_RIGHT);

        tabPanel_.add(widget, panel);
        tabPanel_.getTabWidget(widget).setTitle(tooltip);
        tabPanel_.selectTab(widget);
    }
Hello爱情风 2024-11-16 02:07:26

GWT 本身不支持它。

您可以手动尝试添加。

请阅读此内容 - http://groups.google。 com/group/google-web-toolkit/browse_thread/thread/006bc886c1ccf5e1?pli=1

我个人没有尝试过,但看看gregor 的解决方案(最后一个)。

It isn't supported natively in GWT.

You can manually try to add it.

Read this - http://groups.google.com/group/google-web-toolkit/browse_thread/thread/006bc886c1ccf5e1?pli=1

I haven't tried it personally, but look at the solution by gregor (last one).

苄①跕圉湢 2024-11-16 02:07:21

工作代码是这样的;

    private Widget getTabTitle(final Widget widget, final String title) {

    final HorizontalPanel hPanel = new HorizontalPanel();
    final Label label = new Label(title);
    DOM.setStyleAttribute(label.getElement(), "whiteSpace", "nowrap");

    ImageAnchor closeBtn = new ImageAnchor();
    closeBtn.setResource(images.cross());

    closeBtn.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            int widgetIndex = tabs.getWidgetIndex(widget);
            if (widgetIndex == tabs.getSelectedIndex()) {
                tabs.selectTab(widgetIndex - 1);
            }
            tabs.remove(widgetIndex);               
        }
    });
    hPanel.add(label);
    hPanel.add(new HTML("   "));
    hPanel.add(closeBtn);
    hPanel.setStyleName("gwt-TabLayoutPanelTab");
    return hPanel;
}

为了添加选项卡,

    public void addTab() {
    TabWriting tw = new TabWriting(); /* TabWriting in my case, this can be any widget */
    tabs.add(tw, getTabTitle(tw, "Writing"));
    tabs.selectTab(tw);
}

您将需要 ImageAnchorClass

public class ImageAnchor extends Anchor {

public ImageAnchor() {
}

public void setResource(ImageResource imageResource) {
    Image img = new Image(imageResource);
    img.setStyleName("navbarimg");
    DOM.insertBefore(getElement(), img.getElement(), DOM
            .getFirstChild(getElement()));
}}

the working code is like that;

    private Widget getTabTitle(final Widget widget, final String title) {

    final HorizontalPanel hPanel = new HorizontalPanel();
    final Label label = new Label(title);
    DOM.setStyleAttribute(label.getElement(), "whiteSpace", "nowrap");

    ImageAnchor closeBtn = new ImageAnchor();
    closeBtn.setResource(images.cross());

    closeBtn.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            int widgetIndex = tabs.getWidgetIndex(widget);
            if (widgetIndex == tabs.getSelectedIndex()) {
                tabs.selectTab(widgetIndex - 1);
            }
            tabs.remove(widgetIndex);               
        }
    });
    hPanel.add(label);
    hPanel.add(new HTML("   "));
    hPanel.add(closeBtn);
    hPanel.setStyleName("gwt-TabLayoutPanelTab");
    return hPanel;
}

In order to add tab,

    public void addTab() {
    TabWriting tw = new TabWriting(); /* TabWriting in my case, this can be any widget */
    tabs.add(tw, getTabTitle(tw, "Writing"));
    tabs.selectTab(tw);
}

You'll going to need, ImageAnchorClass

public class ImageAnchor extends Anchor {

public ImageAnchor() {
}

public void setResource(ImageResource imageResource) {
    Image img = new Image(imageResource);
    img.setStyleName("navbarimg");
    DOM.insertBefore(getElement(), img.getElement(), DOM
            .getFirstChild(getElement()));
}}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文