private void rebuildTabs() {

    rebuildingTabs = true;
    for (int i = 0; i < tabbedPane.getTabCount(); i++) {
      SheetPanel sheetPanel = (SheetPanel) tabbedPane.getComponentAt(i);
      sheetPanel.dispose();
    }
    tabbedPane.removeAll();
    Workbook workbook = manager.getWorkbook();
    for (Sheet sheet : workbook.getSheets()) {
      if (!sheet.isHidden()) {
        SheetPanel sheetPanel = new SheetPanel(manager, sheet);
        tabbedPane.add(sheet.getName(), sheetPanel);
      }
    }
    rebuildingTabs = false;
  }
 public void setSelectedSheet(Sheet sheet) {
   for (int i = 0; i < tabbedPane.getTabCount(); i++) {
     SheetPanel sheetPanel = (SheetPanel) tabbedPane.getComponentAt(i);
     if (sheetPanel.getSheet().getName().equals(sheet.getName())) {
       tabbedPane.setSelectedIndex(i);
       break;
     }
   }
 }