Center JDialog over parent

前端 未结 5 729
借酒劲吻你
借酒劲吻你 2020-11-30 09:39

I have a Java swing application with a button that produces a popup window when a certain action is performed. I\'d like to align the center point of the popup window with

5条回答
  •  情书的邮戳
    2020-11-30 10:16

    You can utilize event e to get parent window. Use getWindowAncestor and e.getSource().

    dialog.setLocationRelativeTo(SwingUtilities.getWindowAncestor((Component) e.getSource()))

提交回复
热议问题