Window () { Window[] windows = Window.getWindows(); Window targetWindow = null; for (Window each : windows) { if (each.isActive()) { targetWindow = each; break; } } if (targetWindow == null) { targetWindow = JOptionPane.getRootFrame(); } return targetWindow; }