Add a helper to set window icons.
As the comments say, it tries to use the nicer stuff that was added in 1.6, but falls back as needed. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2963 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -41,9 +41,11 @@ import java.awt.Window;
|
|||||||
import java.awt.geom.Area;
|
import java.awt.geom.Area;
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
@@ -575,6 +577,30 @@ 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.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
public static void setWindowIcons (Window window, List<? extends Image> icons)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use whichever's at the top of the list
|
||||||
|
window.setIconImage(icons.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Aligns the first <code>rows</code> * <code>cols</code> components of <code>parent</code> in
|
* Aligns the first <code>rows</code> * <code>cols</code> components of <code>parent</code> in
|
||||||
* a grid. Each component in a column is as wide as the maximum preferred width of the
|
* a grid. Each component in a column is as wide as the maximum preferred width of the
|
||||||
|
|||||||
Reference in New Issue
Block a user