Here you can find the source of findComponentWithBorder(JComponent panel, Class> aClass)
private static Container findComponentWithBorder(JComponent panel, Class<?> aClass)
//package com.java2s; //License from project: Apache License import javax.swing.*; import java.awt.*; public class Main { private static Container findComponentWithBorder(JComponent panel, Class<?> aClass) { for (int n = 0; n < panel.getComponentCount(); n++) { if (panel.getComponent(n) instanceof JComponent) { JComponent comp = (JComponent) panel.getComponent(n); if (comp.getBorder() != null && aClass.isAssignableFrom(comp.getBorder().getClass())) { return comp; }/*from w ww . j a v a 2 s . c om*/ Container con = findComponentWithBorder(comp, aClass); if (con != null) { return con; } } } return null; } }