LookAndFeelAddons { 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()); } }  void initialize(); void uninitialize(); void loadDefaults(Object[] keysAndValues); void unloadDefaults(@SuppressWarnings("unused") Object[] keysAndValues); static void setAddon(String addonClassName); static void setAddon(Class<?> addonClass); static void setAddon(LookAndFeelAddons addon); static LookAndFeelAddons getAddon(); static String getBestMatchAddonClassName(); static String getCrossPlatformAddonClassName(); static String getSystemAddonClassName(); static void contribute(ComponentAddon component); static void uncontribute(ComponentAddon component); static ComponentUI getUI(JComponent component, Class<?> expectedUIClass); static synchronized void setTrackingLookAndFeelChanges(boolean tracking); static synchronized boolean isTrackingLookAndFeelChanges(); static void installBackgroundPainter(JComponent c, String painter); static void uninstallBackgroundPainter(JComponent c);  }
@Test(expected = IllegalArgumentException.class) public void testInstallBackgroundPainterWithoutPainterCapable() { LookAndFeelAddons.installBackgroundPainter(new JPanel(), null); }
@Test(expected = NullPointerException.class) public void testInstallBackgroundPainterWithNullComponent() { LookAndFeelAddons.installBackgroundPainter(null, "test.painter"); }
@Test(expected = NullPointerException.class) public void testInstallBackgroundPainterWithNullPainterKey() { LookAndFeelAddons.installBackgroundPainter(new BackgroundPainterTestingComponent(), null); }
@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void testInstallBackgroundPainter() { Painter plafPainter = new PainterUIResource(null); UIManager.put("test.painter", plafPainter); BackgroundPainterTestingComponent panel = new BackgroundPainterTestingComponent(); LookAndFeelAddons.installBackgroundPainter(panel, "test.painter"); assertThat(panel.getBackgroundPainter(), is(sameInstance(plafPainter))); panel.setBackgroundPainter(new PainterUIResource(null)); LookAndFeelAddons.installBackgroundPainter(panel, "test.painter"); assertThat(panel.getBackgroundPainter(), is(sameInstance(plafPainter))); Painter userPainter = new MattePainter(); panel.setBackgroundPainter(userPainter); LookAndFeelAddons.installBackgroundPainter(panel, "test.painter"); assertThat(panel.getBackgroundPainter(), is(sameInstance(userPainter))); }