title: JTabbedPane component accessing
body: <p>I use <code>JTabbedPane</code> in one of my Java GUI code. I use the following portion of code to instantiate and maintain the <code>tabpane</code>.</p>
  
  <pre><code>JTabbedPane tabpane =  new JTabbedPane();  
  PageViewer pv = new PageViewer();  
  tabpane.addTab("tabttitle", new JScrollPane(pv));
  </code></pre>
  
  <p><code>PageViewer</code> is an extended class of <code>JEditorPane</code>. I want to access and modify the currently selected tab's constituent <code>PageViewer pv</code> component. I tried the following lines of code with some values of <code>ind</code>.</p>
  
  <pre><code>JScrollPane jsp = (JScrollPane) tabpane.getComponentAt(tabpane.getSelectedIndex());  
  PageViewer pv2 = (PageViewer) jsp.getComponent(ind);
  </code></pre>
  
  <p>But for <code>ind==0</code> compiler says <code>"java.lang.ClassCastException: javax.swing.JViewport cannot be cast to menu_window.PageViewer"</code>.</p>
  
  <p>For <code>ind==1</code> it says <code>"java.lang.ClassCastException: javax.swing.JScrollPane$ScrollBar cannot be cast to menu_window.PageViewer"</code>.</p>
  
  <p>For <code>ind==2</code> output is <code>"java.lang.ClassCastException: javax.swing.JScrollPane$ScrollBar cannot be cast to menu_window.PageViewer"</code>.</p>
  
  <p>And for <code>ind>=3</code> error is <code>"java.lang.ArrayIndexOutOfBoundsException: No such child: 3"</code>.</p>
  
  <p>Now how do I do the desired job, if anyone knows please help.</p>
  
  <p>Note: I use NetBeans 6.8 with Java 6 Standard Edition.</p>