Sub Window(CustomComponent ) can't open when button click

hii all, i’ve try to starting develope web application using vaadin. when i try to create CustomComponent then show it when i click the button, the window i’ve create using extends CustomComponent can’t showing. anyone help me? this my code:

the SubWindows Classs


package com.example.hellovaadin;

import com.vaadin.annotations.AutoGenerated;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

public class SubWindows extends CustomComponent {
	
	Window subwindow;

    public void SubwindowExample() {

        // Create the window
        subwindow = new Window("A subwindow");

        // Configure the windws layout; by default a VerticalLayout
        VerticalLayout layout = (VerticalLayout) subwindow.getContent();
        layout.setMargin(true);
        layout.setSpacing(true);

        // Add some content; a label and a close-button
        Label message = new Label("This is a subwindow");
        subwindow.addComponent(message);

        Button close = new Button("Close", new Button.ClickListener() {
            // inline click-listener
            public void buttonClick(ClickEvent event) {
                // close the window by removing it from the parent window
                (subwindow.getParent()).removeWindow(subwindow);
            }
        });
        // The components added to the window are actually added to the window's
        // layout; you can use either. Alignments are set using the layout
        layout.addComponent(close);
        layout.setComponentAlignment(close, Alignment.TOP_RIGHT);

        // Add a button for opening the subwindow
        Button open = new Button("Open subwindow", new Button.ClickListener() {
            // inline click-listener
            public void buttonClick(ClickEvent event) {
                if (subwindow.getParent() != null) {
                    // window is already showing
                    getWindow().showNotification("Window is already open");
                } else {
                    // Open the subwindow by adding it to the parent window
                    getWindow().addWindow(subwindow);
                }
            }
        });
        addComponent(open);

    }

	

	@AutoGenerated
	private AbsoluteLayout mainLayout;

	/**
	 * The constructor should first build the main layout, set the
	 * composition root and then do any custom initialization.
	 *
	 * The constructor will not be automatically regenerated by the
	 * visual editor.
	 */
	public SubWindows() {
		buildMainLayout();
		setCompositionRoot(mainLayout);

		// TODO add user code here
	}

	@AutoGenerated
	private void buildMainLayout() {
		// the main layout and components will be created here
		mainLayout = new AbsoluteLayout();
	}

}

then on main class i create button by this code:


Button testButton = new Button();
		testButton.setDescription("sub window tes");
		testButton.setCaption("sub window tes");
		testButton.addListener(new Button.ClickListener() {
			
			public void buttonClick(ClickEvent event) {
				SubWindows sub = new SubWindows();
				getMainWindow().addComponent(sub);
				
			}
		});


		VerticalLayout verLayout = new VerticalLayout();
		verLayout.setSpacing(true);
		verLayout.addComponent(testButton);

		mainWindow.addComponent(verLayout);

thanks for advice

SOLVED, i just change


getMainWindow().addComponent(sub);

with this right method:


getMainWindow().setContent(sub);

:lol: