SwingUtilities.getWindowAncestor seems buggy in jdk5 SwingUtilities.getWindowAncestor(Component ComponentThatCouldBeAFrame) seems have issues. Trying to open the file dialog was throwing null pointer exceptions in jdk5. I needed to make another check to see if the component is a frame before creating and displaying the file chooser dialog with jdk5.
Window window = SwingUtilities.getWindowAncestor(parent);
if (window == null)
{
if (parent instanceof Window)
{
window = (Window) parent;
}
else
{
window = new Frame();
}
dialog = new JDialog((Frame) window, title, true);
}
else if (window instanceof Frame)
{
dialog = new JDialog((Frame) window, title, true);
}
else
{
dialog = new JDialog((Dialog) window, title, true);
}
I would like to avoid maintaining 2 branches if possible. There are lots of things that are easily done with jdk6 whereas in jdk5 additional classes are necessary.
No comments:
Post a Comment