How to detect if one swing window is above another one

给你一囗甜甜゛ 提交于 2019-12-05 16:33:52

Simply use Window.isFocusableWindow(), to check as to which JFrame lies on top of all others.

Though I will also insist on not using more than a single JFrame, for any application :-)

mKorbel

QUESTION: How can I detect the deep location each of frames in this case?

UPD: I detect this case by comparing the frames' location/size pairs, but I still do not how to resolve my issue.

  • you can to loop inside arrays of Top-Level Containers

.

  Window[] wins = Window.getWindows();
  for (int i = 0; i < wins.length; i++) {
        if (wins[i] instanceof JFrame) {
            wins[i].wheteverMethodImplementedInConcreteAPI;
        } //else if ... JDialog, JWindow, e.i. AWT Containers
  }

.

Hmm.. I can't find the my question' answer on your link actually...Except the bad bad practise to use several JFrames :)

.

  • see Remove Top-Level Container on Runtime, then there are

    1. use CardLayout instead of bunch of JFrames, without any popup windows

    2. use CardLayout instead of bunch of JFrames and for another popup window to use JDialog()/JWindow(JTextComponents aren't editable)

    3. use CardLayout instead of bunch of JFrames and for another popup window to use JDialog()/JWindow(JTextComponents aren't editable) with CardLayout for multiple switching betweens view in popup container, note usage Xxx.pack() is required for proper sizing after card is switched

    4. set JFrame as parent for JDialog()/JWindow(), then parent v.s. child are question of isVisible, isDisplayable, etc, and rest events implemented in WindowEvent

You can use the getComponentZOrder() to get the z-index of the frames and set it using setComponentZOrder().

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!