How about first getting the selected component of the tab (which is the scroll panel):
JScrollPane jscrollpane =(JScrollPane)jTabbedPane.getSelectedComponent();
And then get the selected component of that (which would be the text panel):
JTextPane jtextpanel=(JTextPane)jscrollpane.getSelectedComponent();
You should do some type checking though to be safe. Also, you could create a recursive method using
getComponents
to find the desired text panel on the tab or scroll panel.
Good luck!