Both the List and Image versions of setIconImage were introduced in 1.6, so it's reflection or

nothing.



git-svn-id: https://samskivert.googlecode.com/svn/trunk@2964 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
charlie.groves
2010-12-02 02:33:59 +00:00
parent 88628a38f4
commit 37e5e05998
@@ -578,27 +578,26 @@ public class SwingUtil
} }
/** /**
* Sets the window's icons. Unfortunately, the ability to pass multiple icons so the OS can * Sets the window's icons.<p>
* choose the most size-appropriate one was added in 1.6; before that, you can only set one
* icon.
* *
* This method attempts to find and use setIconImages, but if it can't, sets the window's icon * Unfortunately, the ability to set the window icon was added in 1.6; if the ability isn't
* to the first icon in the list passed in. * present, this method does nothing.
*/ */
public static void setWindowIcons (Window window, List<? extends Image> icons) public static void setWindowIcons (Window window, List<? extends Image> icons)
{ {
Method m;
try { try {
Method m = window.getClass().getMethod("setIconImages", List.class); m = window.getClass().getMethod("setIconImages", List.class);
if (m != null) { } catch (SecurityException e) {
m.invoke(window, icons); return; // Fine, fine, no reflection for us
return; } catch (NoSuchMethodException e) {
} return;// This is fine, we must be on a pre-1.6 JVM
} catch (Exception e) { }
// It's okay; it's probably just that we're running with an old jvm try {
m.invoke(window, icons);
} catch (Exception e) {
throw new RuntimeException(e);
} }
// Use whichever's at the top of the list
window.setIconImage(icons.get(0));
} }
/** /**