Java tutorial
//package com.java2s; //License from project: Open Source License import java.awt.Component; import java.awt.Container; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JInternalFrame; import javax.swing.JLabel; public class Main { /**Devuelve el componente que tiene el actioncomand psComando*/ public static JComponent getComponente(Container poContenedor, String psAccion) { JComponent loResult = null; for (int i = 0; i < poContenedor.getComponentCount() && loResult == null; i++) { Component loComp = poContenedor.getComponent(i); if (loResult == null && JButton.class.isAssignableFrom(loComp.getClass())) { if (((JButton) loComp).getActionCommand() != null && ((JButton) loComp).getActionCommand().equals(psAccion)) { loResult = ((JButton) loComp); } } if (loResult == null && JLabel.class.isAssignableFrom(loComp.getClass())) { if (((JLabel) loComp).getName() != null && ((JLabel) loComp).getName().equals(psAccion)) { loResult = ((JLabel) loComp); } } if (loResult == null && JComboBox.class.isAssignableFrom(loComp.getClass())) { if (((JComboBox) loComp).getName() != null && ((JComboBox) loComp).getName().equals(psAccion)) { loResult = ((JComboBox) loComp); } } if (loResult == null && JInternalFrame.class.isAssignableFrom(loComp.getClass())) { if (((JInternalFrame) loComp).getName() != null && ((JInternalFrame) loComp).getName().equals(psAccion)) { loResult = ((JInternalFrame) loComp); } } if (loResult == null && Container.class.isAssignableFrom(loComp.getClass())) { loResult = getComponente(((Container) loComp), psAccion); } // if(loComp.getClass().isAssignableFrom(JToolBar.class) ){ // loResult = getComponente(((JToolBar)loComp), psAccion); // } } return loResult; } }