List of usage examples for java.awt Container getName
public String getName()
From source file:Main.java
public static void main(String args[]) { final JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); JButton b = new JButton("Hide for 5"); ActionListener action = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { frame.setVisible(false);/*from ww w. j a va 2s . com*/ TimerTask task = new TimerTask() { public void run() { frame.setVisible(true); } }; Timer timer = new Timer(); timer.schedule(task, 5000); } }; b.addActionListener(action); AncestorListener ancestor = new AncestorListener() { public void ancestorAdded(AncestorEvent e) { System.out.println("Added"); dumpInfo(e); } public void ancestorMoved(AncestorEvent e) { System.out.println("Moved"); dumpInfo(e); } public void ancestorRemoved(AncestorEvent e) { System.out.println("Removed"); dumpInfo(e); } private void dumpInfo(AncestorEvent e) { System.out.println("\tAncestor: " + name(e.getAncestor())); System.out.println("\tAncestorParent: " + name(e.getAncestorParent())); System.out.println("\tComponent: " + name(e.getComponent())); } private String name(Container c) { return (c == null) ? null : c.getName(); } }; b.addAncestorListener(ancestor); contentPane.add(b, BorderLayout.NORTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static <T> T findChildByName(Container container, Class<T> returnType, String name) { if (name.equals(container.getName())) { return returnType.cast(container); }// www. j a va2s . c o m for (Component component : container.getComponents()) { if (name.equals(component.getName())) { return returnType.cast(component); } else if (component instanceof Container) { T recursiveResult = findChildByName((Container) component, returnType, name); if (recursiveResult != null) { return returnType.cast(recursiveResult); } } } throw new IllegalArgumentException( "Did not find child component by name [" + name + "] in the specified container!"); }
From source file:com.hartveld.commons.test.swing.AbstractSwingFrameTest.java
private static <T> T lookup(final Container container, final String name, final Class<T> clazz) { LOG.trace("Looking up component of type {} in container {} ...", clazz.getName(), container.getName()); for (final Component c : container.getComponents()) { if (clazz.isAssignableFrom(c.getClass())) { if (name == null || name.equals(c.getName())) { @SuppressWarnings("unchecked") final T target = (T) c; return target; }/*from w ww.jav a 2s . co m*/ } else if (c instanceof Container) { final T nested = lookup((Container) c, name, clazz); if (nested != null) { return nested; } } } return null; }
From source file:net.sourceforge.squirrel_sql.fw.gui.debug.DebugEventListener.java
private void printDebugInfo(JComponent source, AWTEvent event) { Container parent = source.getParent(); String sourceName = source.getName(); String sourceClassName = source.getClass().toString(); String parentName = parent == null ? null : parent.getName(); String parentClassName = parent == null ? null : parent.getClass().toString(); StringBuilder msg = new StringBuilder(getEventMessagePrefix(event)); msg.append("\n"); msg.append("\t sourceName:").append(sourceName).append("\n"); msg.append("\t sourceClassName:").append(sourceClassName).append("\n"); msg.append("\t parentName:").append(parentName).append("\n"); msg.append("\t parentClassName:").append(parentClassName); System.out.println(msg.toString()); }