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