Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

First use the vaadin and have no idea about the AbstractComponentContainer

Roy Wang
10 years ago Dec 30, 2011 2:00am
Johannes Häyry
10 years ago Dec 30, 2011 1:55pm

Hello and welcome to the community.

As a tip when posting a code, it is good to use the code formatting so your code is easier to read. You can use the code formatting button in the editor or you can wrap your code with markdown tags.

What comes to using CustomComponent, you need to call setCompositionRoot in the CustomComponent constructor (TheButtons). Anyway there's not really a point to extend CustomComponent if you then plan to provide the container (or do you actually mean a Layout) outside its implementation. In the Application class where you are creating a new CustomComponent the same issue is present. You have to set a composition root.

Last updated on Dec, 30th 2011
Roy Wang
10 years ago Jan 03, 2012 12:40am
Roy Wang
10 years ago Jan 03, 2012 1:14am
Bobby Bissett
10 years ago Jan 03, 2012 5:42pm

Hi,

Window is an abstract component container, so after you create your main Window object you can pass it to the constructor of TheButton to create a button. Something like this:

@Override
    public void init(){
        Window mainWindow = new Window("My Window");
        TheButton theButton = new TheButton(mainWindow);
        setMainWindow(mainWindow);
    }

It's really a question of preference, but I prefer to not have listeners do the addComponent call. For instance, this would be my application's init method:

@Override
    public void init(){
        Window mainWindow = new Window("My Window");
        Button button = new Button ("Do not push this button",
            new TheButtonListener());
        mainWindow.addComponent(button);
        setMainWindow(mainWindow);
    }

...and then your TheButton class (which I renamed for the example) could simply implement the buttonClick method. Inside that method, you can call getButton() on the click event to get a reference to the button that was clicked.

Cheers,
Bobby

Last updated on Jan, 3rd 2012
Roy Wang
10 years ago Jan 04, 2012 1:09am

Thank you for your help and the method is very suitable for me.Thank you