HidableTabbedPane extends JPanel { public void removeTabAt(int index) { tabs.removeTabAt(index); if (tabs.getTabCount() >= 1) { firstComponent = tabs.getComponentAt(0); } if (tabs.getTabCount() == 1) { hideTabs(); } } HidableTabbedPane();  HidableTabbedPane(String firstTabTitle, Component firstComponent); int getTabCount(); int getSelectedIndex(); void setSelectedIndex(int index); Component getComponentAt(int index); Component getTabComponentAt(int index); void setComponentAt(int index, Component component); void setTabComponentAt(int index, Component component); boolean isTabsShown(); void addTab(String title, Component component); void removeTabAt(int index); void addChangeListener(ChangeListener listener);  }
@Test public void testRemoveTabAt() throws Exception { HidableTabbedPane h; JLabel one = new JLabel("One"); JLabel two = new JLabel("Two"); JLabel three = new JLabel("Three"); JLabel four = new JLabel("Three"); h = new HidableTabbedPane("Tab One", one); h.addTab("Tab Two", two); h.addTab("Tab Three", three); h.addTab("Tab Four", four); assertEquals(h.getTabCount(), 4); assertEquals(h.getComponentAt(0), one); assertEquals(h.getComponentAt(1), two); assertEquals(h.getComponentAt(2), three); assertEquals(h.getComponentAt(3), four); h.removeTabAt(2); assertEquals(h.getTabCount(), 3); assertEquals(h.getComponentAt(0), one); assertEquals(h.getComponentAt(1), two); assertEquals(h.getComponentAt(2), four); h.removeTabAt(0); assertEquals(h.getTabCount(), 2); assertEquals(h.getComponentAt(0), two); assertEquals(h.getComponentAt(1), four); h.removeTabAt(0); assertEquals(h.getTabCount(), 1); assertEquals(h.getComponentAt(0), four); h.removeTabAt(0); assertEquals(h.getTabCount(), 0); }