java - 如何根据 vaadin 中的操作重新加载或刷新选项卡的内容

标签 java tabs actionlistener vaadin

选项卡的内容是在加载应用程序时形成并显示的。稍后选项卡的内容可能会被其他操作更改。我想在每次操作后显示较新的内容。每次我单击选项卡时,内容都应该刷新/更新。但我失败了。

    //the content of the tab from the "reprintsTab" class
    //in the "reprintsTab" it query data from database and print out
    //later I update the data in the database from somewhere else, and I want the tab shows the new content
    //I want to click the tab sheet to reload the "reprintTab" class and print out the new content

    //here is what I did:

    public TabSheet sheet;

    //add tab and add the content from "reprintTab" into this tab
    sheet.addTab(new reprintsTab());

    //add the listener 
    sheet.addListener(new TabSheet.SelectedTabChangeListener() {

        @Override
        public void selectedTabChange(SelectedTabChangeEvent event) {

        //I know it does not work, because it only reload the class. but not put the content under the tab I want
        new reprintsTab();

        }
    });

我该怎么办?请帮助我,谢谢。

最佳答案

您可以使用TabSheet.replaceComponent方法:

//Field to store current component
private reprintsTab currentComponent; 

//during initialization
currentComponent = new reprintsTab();
sheet.addTab(currentComponent);

sheet.addListener(new TabSheet.SelectedTabChangeListener() {
    @Override
    public void selectedTabChange(SelectedTabChangeEvent event) {
        reprintsTab newComponent = new reprintsTab();
        sheet.replaceComponent(currentComponent, newComponent);
        currentComponent = newComponent;
    }
});

此外,您可能只想在显示此选项卡时重新加载它:

sheet.addListener(new TabSheet.SelectedTabChangeListener() {
        @Override
        public void selectedTabChange(SelectedTabChangeEvent event) {
            if (event.getTabSheet().getSelectedTab() == currentComponent) {
                //here goes the code
            }
        }
});

这应该适合您,但我建议采用一种更简洁的方法:将 reprintsTab 实现为组件容器,创建方法 reloadbuildInterface > 方法来刷新其状态,因此您只需调用:

currentComponent.reload();

当你需要更新界面时。

另外,我希望reprintsTab只是一个示例名称,以小写字母开头的java类名看起来很难看。

关于java - 如何根据 vaadin 中的操作重新加载或刷新选项卡的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15378425/

相关文章:

java - 不会为 CheckBox 触发 ActionListener 类

java - 如何在调用 wsdl 链接时隐藏/删除 "<!--WSDL created by Apache Axis version: 1.4 Built on Apr 22, 2006 (06:55:48 PDT)-->"

ios - 我添加了选项卡,但无法访问选项卡外的 View (ios)

python - 以 3 为一组打印 python 列表

java - 如何在 ComboBox 上使用 ActionListener 为变量赋值

java - 如何使用 Java2D 在 GUI 中使用 ActionListener 调用方法

java - 使用 Jasypt 时获取密码 Salt

java - 使用 null int 的 Gson 反序列化似乎无法正常工作

reactjs - 如何在react-bootstrap中调用更改的选项卡上的事件

java - ActionPerformed 自执行