Dynamic Tab Editable

Hi ,
This code will create Tabs. namely “Sample” and “+” . Two Tabs(Sample, + ). when click on + tab, This code will generate dynamic tabs. Say for Example (Sample, +, The new Tab). I need to edit Dynmic tab name that is The new Tab. Could you please help me

package com.example.dynamictab;
import javax.servlet.annotation.WebServlet;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Label;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
import com.vaadin.ui.TabSheet.SelectedTabChangeListener;
import com.vaadin.ui.TabSheet.Tab;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings(“serial”)
@Theme(“dynamictab”)
public class DynamictabUI extends UI {
@WebServlet(value = “/*”, asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = DynamictabUI.class)
public static class Servlet extends VaadinServlet {
}
@Override
protected void init(VaadinRequest request) {

    VerticalLayout verticalLayout = new VerticalLayout();
    final TabSheet tabSheet = new TabSheet();
    final Tab sampleTab = tabSheet.addTab(new Label("Contents of the first tab"),"Sample");
    tabSheet.addTab(new Label("Contents of the first tab"),"+");
    tabSheet.setImmediate(true);
    tabSheet.addSelectedTabChangeListener(new SelectedTabChangeListener() {

    @Override
    public void selectedTabChange(SelectedTabChangeEvent event) {
    TabSheet tabsheet = event.getTabSheet();
    Tab selectedTab = tabsheet.getTab(tabsheet.getSelectedTab());
    if (selectedTab != null) {
    if(selectedTab.getCaption().equals("+")){
           VerticalLayout newTabLayout = new VerticalLayout();
           Tab tab = tabSheet.addTab(newTabLayout, "The new Tab", null);
           int newPosition = tabSheet.getTabPosition(tab);
           tabSheet.setTabPosition(tab,newPosition-1 );
           tabSheet.setTabPosition(selectedTab,newPosition );
           tabSheet.setSelectedTab(tab);
                              
    }        }        }        });

    verticalLayout.addComponent(tabSheet);
    //verticalLayout.addComponent(button);
    setContent(verticalLayout);
    } // End Loop


}

Did you take a look at this addon?
https://vaadin.com/directory#addon/dynamictabsheet:vaadin

Below code is excellent sir, Thank you for your help. If I Click on add new Tab, i want to make it as editable. could you please let me know sir, i am new to vaadin

DynamicTabSheet tabSheet = new DynamicTabSheet(); tabSheet.addComponent(new Button(“loooooooooooog caption”)); layout.addComponent(tabSheet); tabSheet.setAddButtonClickListener(new AddButtonClickListener() { @Override public void onAddNewTab() { Notification.show(“add new Tab”); } });

Sorry, I didn’t understand your question clearly. Do you want the caption of the newly added tab to be editable? I guess this is no easy way to make the caption itself direclty editable.
Instead, you can add a TextField to your ‘newTabLayout’, and in the ValuchangeListner, you can set the caption of the tab by tabSheet.getTab(newTabLayout).setCaption(...)

Yes, Sir you are correct. I want to edit newly added tab only. Thanks