Pop-up window in Java Swing

一曲冷凌霜 提交于 2019-12-04 01:09:25

问题


Can someone suggest me how to implement a pop-up window in Java Swing. I want the pop-up window to be a modal window (user cannot return to the main window when the pop-up is open).

I tried doing it using JDialog but it allows only one widget for user input to be in it whereas I need multiple widgets. I may be wrong here but this is what I was able to do.

Appreciate your help.


回答1:


Use a JDialog. There is no restiction on what you can add, you can add whatever you want to a JDialog (exactly the same as when using a JFrame)




回答2:


  1. Layout your widgets in a JPanel.

  2. Use JOptionPane.showConfirmDialog with your panel as the message (with, for example, optionType JOptionPane.OK_CANCEL_OPTION).

  3. Read user input from your panel's state when appropriate (for example, the call returns JOptionPane.OK_OPTION rather than JOptionPane.CANCEL_OPTION).




回答3:


I hope i found the right info for you

JDialog(Dialog owner, boolean modal)

for more information check this links: http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/modality/

http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html



来源:https://stackoverflow.com/questions/2405039/pop-up-window-in-java-swing

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