What do you mean by closing from code? If you mean to remove the tab, just calling tabPanel.remove(widget) or tabPanel.remove(i) (where i is the tab index) will remove the tab.
If you mean to make the tab available to be closed by the user, modify its TabItemConfig instance to set its closable property to true.