通过该布局上的子按钮更改父布局

发布于 2024-11-01 00:02:53 字数 147 浏览 0 评论 0原文

我在通过单击位于该面板上的按钮上的事件来更改选项卡面板布局时遇到问题。主要思想是在每个选项卡面板上的小面板上都有自定义菜单(新建、打开、删除)。当您单击按钮时,选项卡面板布局将更改为表单(例如)。我不想使用模式窗口或新窗口,只需通过单击按钮将选项卡面板布局(内容)更改为其他内容。

I have problem with change of tab panel layout by click event on buton located on that panel. The main idea is to have custom menu (new, open, del) on smal panel on every tab panel. When you click button, tab panel layout is change to form (for example). I don't want use modal window or new window, just change the tab panel layout (content) to something else by button click.

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

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

发布评论

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

评论(1

¢好甜 2024-11-08 00:02:53

这是错误的指定问题 - 您应该询问如何通知父组件。
下面有两个例子展示了如何实现你的目标。第一个实现按照 Jens Janssons 在 vaadin 论坛上的建议进行,您将 ClickListener 作为构造函数参数传递给第二个面板。请注意,为了能够从外部面板中移除组件,您需要外部面板和内部面板的引用。在此示例中,Kim Lappanen 将引用存储在类变量中。请注意,实际上使用了 Horizo​​ntalLayout 作为您所谓的“面板”,您可以更改它。

public class TestcaseApplication extends Application implements ClickListener {
    private static final long serialVersionUID = 75232258896642392L;

    private final HorizontalLayout mainLayout = new HorizontalLayout();
    private final YourPanel panel = new YourPanel(this);

    @Override
    public void init() {
        setTheme("example");
        Window mainWindow = new Window("Playground Application");
        setMainWindow(mainWindow);

        mainWindow.setContent(mainLayout);

        mainLayout.addComponent(panel);
    }

    public void buttonClick(ClickEvent event) {
        mainLayout.removeComponent(panel);
    }

    public class YourPanel extends Panel {

        public YourPanel(ClickListener listener) {
            super();
            addComponent(new Button("Remove", listener));
        }
    }
}

另一个例子是直接在内部面板中实现 ClickListener。在 ButtonClick 方法中,我只需调用 getParent() (返回输出布局),然后将其自身从该布局中删除。

public class TestcaseApplication extends Application {
    private static final long serialVersionUID = 75232258896642392L;

    @Override
    public void init() {
        setTheme("example");
        Window mainWindow = new Window("Playground Application");
        setMainWindow(mainWindow);

        HorizontalLayout mainLayout = new HorizontalLayout();
        mainWindow.setContent(mainLayout);

        mainLayout.addComponent(new YourPanel());
    }

    public class YourPanel extends Panel implements ClickListener {

        public YourPanel() {
            super();
            addComponent(new Button("Remove", this));

        }

        public void buttonClick(ClickEvent event) {
            ((ComponentContainer) getParent()).removeComponent(this);
        }
    }

}

It, is wrong specified question - you should ask how to notify parent component.
Bellow you have two examples show how to achive your goals. This first implementation does what Jens Janssons suggest on vaadin forum, you pass the ClickListener to the second panel as a constructor parameter. Note that to be able to remove the component from the outer panel, you need both a reference to the outer panel and to the inner panel. In this example Kim Lappanen stored the references in class variables. Note that ther is actually used a HorizontalLayout for what you called your "panel", you can change it.

public class TestcaseApplication extends Application implements ClickListener {
    private static final long serialVersionUID = 75232258896642392L;

    private final HorizontalLayout mainLayout = new HorizontalLayout();
    private final YourPanel panel = new YourPanel(this);

    @Override
    public void init() {
        setTheme("example");
        Window mainWindow = new Window("Playground Application");
        setMainWindow(mainWindow);

        mainWindow.setContent(mainLayout);

        mainLayout.addComponent(panel);
    }

    public void buttonClick(ClickEvent event) {
        mainLayout.removeComponent(panel);
    }

    public class YourPanel extends Panel {

        public YourPanel(ClickListener listener) {
            super();
            addComponent(new Button("Remove", listener));
        }
    }
}

Antoher example is to implement the ClickListener directly in the inner panel. In the buttonClick method, I just call getParent() (returns the out layout) and then removes itself from that layout.

public class TestcaseApplication extends Application {
    private static final long serialVersionUID = 75232258896642392L;

    @Override
    public void init() {
        setTheme("example");
        Window mainWindow = new Window("Playground Application");
        setMainWindow(mainWindow);

        HorizontalLayout mainLayout = new HorizontalLayout();
        mainWindow.setContent(mainLayout);

        mainLayout.addComponent(new YourPanel());
    }

    public class YourPanel extends Panel implements ClickListener {

        public YourPanel() {
            super();
            addComponent(new Button("Remove", this));

        }

        public void buttonClick(ClickEvent event) {
            ((ComponentContainer) getParent()).removeComponent(this);
        }
    }

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