Java tutorial
//package com.java2s; /* * Copyright 2007, Plutext Pty Ltd. * * This file is part of Docx4all. Docx4all is free software: you can redistribute it and/or modify it under the terms of version 3 of the GNU General Public License as published by the Free Software Foundation. Docx4all is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Docx4all. If not, see <http://www.gnu.org/licenses/>. */ import java.awt.Component; import java.awt.Container; import javax.swing.JEditorPane; import javax.swing.JInternalFrame; public class Main { public final static JEditorPane getSourceEditor(JInternalFrame iframe) { return (JEditorPane) getDescendantOfClass(JEditorPane.class, iframe.getContentPane(), true); } public final static Component getDescendantOfClass(Class<?> c, Container comp, boolean exactInstance) { Component theObject = null; if (c != null && comp != null) { Component[] carray = comp.getComponents(); if (carray != null) { for (int i = 0; i < carray.length && theObject == null; i++) { if (exactInstance && carray[i].getClass() == c) { theObject = carray[i]; } else if (!exactInstance && c.isInstance(carray[i])) { theObject = carray[i]; } else if (carray[i] instanceof Container) { theObject = getDescendantOfClass(c, (Container) carray[i], exactInstance); } } } } return theObject; } }