setter.invoke(c, UIManagerExt.getPainter(painter));
/** * Convenience method for setting a component's background painter property with a value from * the defaults. The painter is only set if the painter is {@code null} or an instance of * {@code UIResource}. * * @param c * component to set the painter on * @param painter * key specifying the painter * @throws NullPointerException * if the component or painter is {@code null} * @throws IllegalArgumentException * if the component does not contain the "backgroundPainter" property or the * property cannot be set */ public static void installBackgroundPainter(JComponent c, String painter) { Class<?> clazz = c.getClass(); try { Method getter = clazz.getMethod("getBackgroundPainter"); Method setter = clazz.getMethod("setBackgroundPainter", Painter.class); Painter<?> p = (Painter<?>) getter.invoke(c); if (p == null || p instanceof UIResource) { setter.invoke(c, UIManagerExt.getPainter(painter)); } } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("cannot set painter on " + c.getClass()); } }
/** * Convenience method for setting a component's background painter property with a value from * the defaults. The painter is only set if the painter is {@code null} or an instance of * {@code UIResource}. * * @param c * component to set the painter on * @param painter * key specifying the painter * @throws NullPointerException * if the component or painter is {@code null} * @throws IllegalArgumentException * if the component does not contain the "backgroundPainter" property or the * property cannot be set */ public static void installBackgroundPainter(JComponent c, String painter) { Class<?> clazz = c.getClass(); try { Method getter = clazz.getMethod("getBackgroundPainter"); Method setter = clazz.getMethod("setBackgroundPainter", Painter.class); Painter<?> p = (Painter<?>) getter.invoke(c); if (p == null || p instanceof UIResource) { setter.invoke(c, UIManagerExt.getPainter(painter)); } } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("cannot set painter on " + c.getClass()); } }
/** * Convenience method for setting a component's background painter property with a value from * the defaults. The painter is only set if the painter is {@code null} or an instance of * {@code UIResource}. * * @param c * component to set the painter on * @param painter * key specifying the painter * @throws NullPointerException * if the component or painter is {@code null} * @throws IllegalArgumentException * if the component does not contain the "backgroundPainter" property or the * property cannot be set */ public static void installBackgroundPainter(JComponent c, String painter) { Class<?> clazz = c.getClass(); try { Method getter = clazz.getMethod("getBackgroundPainter"); Method setter = clazz.getMethod("setBackgroundPainter", Painter.class); Painter<?> p = (Painter<?>) getter.invoke(c); if (p == null || p instanceof UIResource) { setter.invoke(c, UIManagerExt.getPainter(painter)); } } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("cannot set painter on " + c.getClass()); } }