Creating own Button via Java

I create an own class IconButton

public class IconButton extends Div{
	
	private Button button;
	public IconButton(String text, ICON_POSITION iconPosition, VaadinIcon vaadinIcon ) {
		if (iconPosition==ICON_POSITION.TOP) {
			Div divText = new Div();
			divText.setText(text);
			Icon icon = new Icon(vaadinIcon);
			button = new Button();
			button.setHeight("50px");
			button.getElement().appendChild(icon.getElement());
			button.getElement().appendChild(divText.getElement());
		}
		
		if (iconPosition==ICON_POSITION.BOTTOM) {
			Div divText = new Div();
			divText.setText(text);
			Icon icon = new Icon(vaadinIcon);
			button = new Button();
			button.setHeight("50px");
			button.getElement().appendChild(divText.getElement());
			button.getElement().appendChild(icon.getElement());
		}
		
		if (iconPosition==ICON_POSITION.LEFT) {
			Icon icon = new Icon(vaadinIcon);
			button = new Button(text);
			button.setHeight("50px");
			button.setIcon(icon);
		}
	}
	
	public enum ICON_POSITION {
		TOP, LEFT, BOTTOM, RIGHT;
	}
	
	public Button getButton() {
		return button;
	}

	public void setButton(Button button) {
		this.button = button;
	}
}

The button appears in the right way.

How can i add this IconButton to my page

IconButton icb = new IconButton("Top", ICON_POSITION.TOP, VaadinIcon.COG_O);
add(icb)

add(icb) works not!

Hi,

Your IconButton has no component. You should add your button in your constructor.

your button needs to added to the container, eg getContent().add(button);

thanks