From b84a696da23223c898cfa2714930f4449cad1b7a Mon Sep 17 00:00:00 2001 From: "karma@deadmoose.com" Date: Thu, 2 Dec 2010 19:26:46 +0000 Subject: [PATCH] Argh. 1.5 has setIconImage on Frame, not Window. It's not that it didn't exist, it just used to be on Frame. So when I did all my 1.5 testing, I was working with a JFrame, and then at the 11th hour decided to make this function take as general a thing as possible, so I merrily climbed up the tree in 1.6 & didn't notice that change. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2965 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../com/samskivert/swing/util/SwingUtil.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/samskivert/swing/util/SwingUtil.java b/src/main/java/com/samskivert/swing/util/SwingUtil.java index 81791005..539e4f41 100644 --- a/src/main/java/com/samskivert/swing/util/SwingUtil.java +++ b/src/main/java/com/samskivert/swing/util/SwingUtil.java @@ -26,6 +26,7 @@ import java.awt.Container; import java.awt.Cursor; import java.awt.Dimension; import java.awt.FontMetrics; +import java.awt.Frame; import java.awt.Graphics2D; import java.awt.Graphics; import java.awt.GraphicsEnvironment; @@ -67,6 +68,8 @@ import javax.swing.table.TableModel; import com.samskivert.util.SortableArrayList; +import static com.samskivert.Log.log; + /** * Miscellaneous useful Swing-related utility functions. */ @@ -578,26 +581,31 @@ public class SwingUtil } /** - * Sets the window's icons.

+ * Sets the frame'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. * - * Unfortunately, the ability to set the window icon was added in 1.6; if the ability isn't - * present, this method does nothing. + * This method attempts to find and use setIconImages, but if it can't, sets the frame's icon + * to the first image in the list passed in. */ - public static void setWindowIcons (Window window, List icons) + public static void setFrameIcons (Frame frame, List icons) { - Method m; try { - m = window.getClass().getMethod("setIconImages", List.class); + Method m = frame.getClass().getMethod("setIconImages", List.class); + m.invoke(frame, icons); + return; } catch (SecurityException e) { - return; // Fine, fine, no reflection for us + // 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); + // This is fine, we must be on a pre-1.6 JVM } catch (Exception e) { - throw new RuntimeException(e); + // Something else went awry? Log it + log.warning("Error setting frame icons", "frame", frame, "icons", icons, "e", e); } + + // We couldn't find it, couldn't reflect, or something. + // Just use whichever's at the top of the list + frame.setIconImage(icons.get(0)); } /**