gpt4 book ai didi

java - Vaadin 子窗口无法关闭

转载 作者:行者123 更新时间:2023-12-02 02:11:50 25 4
gpt4 key购买 nike

我创建的子窗口没有关闭。我看到有些人遇到了同样的问题并发布了同样的问题,但我仍然找不到解决方案。我查过this , and this , and this , and that并且找不到解决方案。下面是我的窗口相应类的代码:

public class CommunicationConfigWindow extends Window
{
private static CommunicationConfigWindow INSTANCE;
private final Accordion catAccordion = new Accordion();
private final VerticalLayout layout = new VerticalLayout();
private final HorizontalLayout toolbar = new HorizontalLayout();
private final Button applyButton = new Button( "Save&Close" );
private final Button cancelButton = new Button( "Cancel" );

private CommunicationConfigWindow( )
{
this.toolbar.setDefaultComponentAlignment( Alignment.MIDDLE_CENTER );
this.applyButton.setSizeFull();

this.cancelButton.addClickListener( e -> {
UI.getCurrent().removeWindow( this );
this.close();
} );
this.applyButton.addStyleName( ValoTheme.BUTTON_FRIENDLY );
this.cancelButton.addStyleName( ValoTheme.BUTTON_DANGER );

this.cancelButton.setSizeFull();
this.toolbar.addComponents( this.cancelButton, this.applyButton );
this.toolbar.setSizeFull();
this.catAccordion.addTab( new GeneralCatLayer( CatVersionEnum.CAT21 ), "CAT 21" );
this.catAccordion.addTab( new GeneralCatLayer( CatVersionEnum.CAT23 ), "CAT 23" );
this.catAccordion.addTab( new GeneralCatLayer( CatVersionEnum.CAT247 ), "CAT 247" );
this.layout.addComponents( this.catAccordion, this.toolbar );
this.setContent( this.layout );

}


public static CommunicationConfigWindow getINSTANCE()
{
if ( CommunicationConfigWindow.INSTANCE == null )
{
CommunicationConfigWindow.INSTANCE = new CommunicationConfigWindow();
}
return CommunicationConfigWindow.INSTANCE;
}


}

This is before I click on cancel. This is after I click on cancel.

我确实从显示设置按钮弹出此窗口。发生的情况是:

  1. 我点击“显示设置”按钮,随即弹出窗口。
  2. 之前我单击“取消”,单击“显示设置”按钮,但自其单例以来它不会创建新窗口。
  3. 我点击“取消”,然后再次点击“显示设置”按钮,旧的困惑的按钮仍保留在那里,并且还创建了一个新窗口。

我基本上希望当我单击取消或关闭按钮时窗口消失,但它根本没有。为什么?

提前致谢。

最佳答案

您的单例可能有问题。你真的需要单例窗口吗?

如果您只想在按钮上添加一个窗口,请单击。您可以尝试进行一些验证,例如

 Window yourWindow = new Window();
if (UI.getCurrent().getWindows().contains(yourWindow)) {
getUI().addWindow(yourWindow);
}

覆盖窗口类中的 equals

关于java - Vaadin 子窗口无法关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49899491/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com