Here you can find the source of getProperties(JComponent component)
Parameter | Description |
---|---|
component | the component whose proerties are to be determined |
public static Map<Object, Object> getProperties(JComponent component)
//package com.java2s; //License from project: Open Source License import javax.swing.*; import java.awt.*; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.*; public class Main { /**// w ww.java 2 s . c o m * Exclude methods that return values that are meaningless to the user */ static Set<String> setExclude = new HashSet<String>(); /** * Convenience method for obtaining most non-null human readable properties * of a JComponent. Array properties are not included. * <P> * Implementation note: The returned value is a HashMap. This is subject * to change, so callers should code against the interface Map. * * @param component the component whose proerties are to be determined * @return the class and value of the properties */ public static Map<Object, Object> getProperties(JComponent component) { Map<Object, Object> retVal = new HashMap<Object, Object>(); Class<?> clazz = component.getClass(); Method[] methods = clazz.getMethods(); Object value = null; for (Method method : methods) { if (method.getName().matches("^(is|get).*") && method.getParameterTypes().length == 0) { try { Class returnType = method.getReturnType(); if (returnType != void.class && !returnType.getName().startsWith("[") && !setExclude.contains(method.getName())) { String key = method.getName(); value = method.invoke(component); if (value != null && !(value instanceof Component)) { retVal.put(key, value); } } // ignore exceptions that arise if the property could not be accessed } catch (IllegalAccessException ex) { } catch (IllegalArgumentException ex) { } catch (InvocationTargetException ex) { } } } return retVal; } }