From 37e5e05998a3669542193e5bda279249a332a9a8 Mon Sep 17 00:00:00 2001 From: "charlie.groves" Date: Thu, 2 Dec 2010 02:33:59 +0000 Subject: [PATCH] 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 --- .../com/samskivert/swing/util/SwingUtil.java | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/samskivert/swing/util/SwingUtil.java b/src/main/java/com/samskivert/swing/util/SwingUtil.java index 4c1cbba7..81791005 100644 --- a/src/main/java/com/samskivert/swing/util/SwingUtil.java +++ b/src/main/java/com/samskivert/swing/util/SwingUtil.java @@ -578,27 +578,26 @@ public class SwingUtil } /** - * Sets the window's icons. Unfortunately, the ability to pass multiple icons so the OS can - * choose the most size-appropriate one was added in 1.6; before that, you can only set one - * icon. + * Sets the window's icons.

* - * This method attempts to find and use setIconImages, but if it can't, sets the window's icon - * to the first icon in the list passed in. + * Unfortunately, the ability to set the window icon was added in 1.6; if the ability isn't + * present, this method does nothing. */ public static void setWindowIcons (Window window, List icons) { + Method m; try { - Method m = window.getClass().getMethod("setIconImages", List.class); - if (m != null) { - m.invoke(window, icons); - return; - } - } catch (Exception e) { - // It's okay; it's probably just that we're running with an old jvm + m = window.getClass().getMethod("setIconImages", List.class); + } catch (SecurityException e) { + return; // Fine, fine, no reflection for us + } catch (NoSuchMethodException e) { + return;// This is fine, we must be on a pre-1.6 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)); } /**