frameJFrame私のSwingアプリで唯一です。JFrameextends以来Window、説明とメソッド名から、コードはフレーム自体を返す必要があると信じていました。
SwingUtilities.windowForComponent(frame)
public static Window windowForComponent(Component aComponent)
コンポーネントのウィンドウを返す
しかしnull、実装はこのようなものであるため、それは を返します
public static Window windowForComponent(Component c) {
return getWindowAncestor(c);
}
public static Window getWindowAncestor(Component c) {
for(Container p = c.getParent(); p != null; p = p.getParent()) {
if (p instanceof Window) {
return (Window)p;
}
}
return null;
}
メソッドの実装が正確ではないことに同意しますか?
UPD: JFrame がメソッドに渡されwindowForComponent、JFrame拡張Windowされるため、次のような追加のチェックが必要です。
if (c instanceof Window) return (Window)c; //in windowForComponent
UPD2:だから私は実装する必要があります
public static Window windowForComponent (Component c) {
if (c instanceof Window)
return (Window)c;
return SwingUtilities.windowForComponent(c);
}