Java Swing 中的弹出窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2405039/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pop-up window in Java Swing
提问by Gaurav Panwar
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).
有人可以建议我如何在 Java Swing 中实现弹出窗口。我希望弹出窗口是一个模态窗口(当弹出窗口打开时,用户无法返回主窗口)。
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.
我尝试使用 JDialog 执行此操作,但它只允许一个小部件供用户输入,而我需要多个小部件。我可能在这里错了,但这是我能够做的。
Appreciate your help.
感谢你的帮助。
采纳答案by objects
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)
使用 JDialog。可以添加的内容没有限制,您可以向 JDialog 添加任何您想要的内容(与使用 JFrame 时完全相同)
回答by Dimitri
I hope i found the right info for you
我希望我找到了适合你的信息
JDialog(Dialog owner, boolean modal)
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/developer/technicalArticles/J2SE/Desktop/javase6/modality/
http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html
http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html
回答by Noel Ang
Layout your widgets in a JPanel.
Use JOptionPane.showConfirmDialog with your panel as the message (with, for example, optionType JOptionPane.OK_CANCEL_OPTION).
Read user input from your panel's state when appropriate (for example, the call returns JOptionPane.OK_OPTION rather than JOptionPane.CANCEL_OPTION).
在 JPanel 中布局您的小部件。
将 JOptionPane.showConfirmDialog 与您的面板一起用作消息(例如,使用 optionType JOptionPane.OK_CANCEL_OPTION)。
在适当的时候从面板状态读取用户输入(例如,调用返回 JOptionPane.OK_OPTION 而不是 JOptionPane.CANCEL_OPTION)。