I've got a JTabbedPane and i need to substitute tab 1 component when user select it. I can't directly add the right component at application start because i don't have full data to generate it.
I need something like this:
int tabTochange = 1;
tabbedPane.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
if (tabbedPane.getSelectedIndex() == tabTochange)
{
JComponent component = generataComponent();
tabbedPane.removeTabAt(tabTochange); // Remove old tab
// add new one
tabbedPane.insertTab("title", null, component, "tip", tabTochange);
}
}
});
But this code doesn't work, it removes the tab other tabs after tab 1 and duplicate it.