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
This commit is contained in:
@@ -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.<p>
|
||||
* 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<? extends Image> icons)
|
||||
public static void setFrameIcons (Frame frame, List<? extends Image> 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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user