SwingアプリケーションgetLocationOnScreen()
から呼び出します。JFrame
が-32000に最小化されている場合JFrame
、-32000が返されます。
それは期待されています:
X = -32000、Y=-32000を示すコンピューター上の位置座標
ただし、ウィンドウを最小化する前にウィンドウの位置を知る必要があります。実際に最大化せずに再度最大化した場合の位置になります。最小化してもJDialog
相対的に配置する必要があるからです。JFrame
考えられる解決策:イベント
に追加WindowListener
してJFrame
、windowIconified()
座標を保存します。そして、の代わりにそれを使用しますgetLocationOnScreen()
。
JFrame
メソッドのみを使用するより良い解決策はありますか?
マルチスクリーン構成が想定されており、次のコードが使用されます。
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
for (int j = 0; j < gs.length; j++) {
GraphicsDevice gd = gs[j];
GraphicsConfiguration[] gc = gd.getConfigurations();
for (int i = 0; i < gc.length; i++) {
Rectangle gcBounds = gc[i].getBounds();
Point loc = topContainer.getLocationOnScreen(); //might return -32000 when minimized
if (gcBounds.contains(loc)) { //fails if -32000 is returned