java - 我可以以非模态方式使用 Java JOptionPane 吗?

标签 java joptionpane

我正在开发一个应用程序,它会在发生特定操作时弹出 JOptionPane。我只是想知道是否有可能当 JOptionPane 弹出时您如何仍然使用后台应用程序。目前,当 JOptionPane 弹出时,在关闭 JOptionPane 之前我无法执行任何其他操作。

编辑

感谢大家的回复和信息。认为我将此功能排除在应用程序之外,因为它看起来可能比必要的更麻烦。

最佳答案

文档明确指出 all dialogs are modal通过 showXXXDialog 方法创建时。

您可以使用从文档中获取的直接使用方法和 setModal JDialog继承自Dialog的方法:

 JOptionPane pane = new JOptionPane(arguments);
 // Configure via set methods
 JDialog dialog = pane.createDialog(parentComponent, title);
 // the line below is added to the example from the docs
 dialog.setModal(false); // this says not to block background components
 dialog.show();
 Object selectedValue = pane.getValue();
 if(selectedValue == null)
   return CLOSED_OPTION;
 //If there is not an array of option buttons:
 if(options == null) {
   if(selectedValue instanceof Integer)
      return ((Integer)selectedValue).intValue();
   return CLOSED_OPTION;
 }
 //If there is an array of option buttons:
 for(int counter = 0, maxCounter = options.length;
    counter < maxCounter; counter++) {
    if(options[counter].equals(selectedValue))
    return counter;
 }
 return CLOSED_OPTION;

关于java - 我可以以非模态方式使用 Java JOptionPane 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5706455/

相关文章:

java - 未调用 Servlet 过滤器

java - GWT SuggestBox : How do I force the SuggestBox to select the first item in the suggestion list?

java - 禁用 JOptionPane.dialog 上的确定按钮,直到用户提供输入

java - android 读/写用户首选项

java - spark SAVEASTEXTfile需要很多时间-1.6.3

java - 将字符串的一部分转换为 int 以从二进制转换为浮点 JAVA 的最佳方法

java - 带有两个标签的 JOptionPane

java - JPanel 调整大小未发生

java - JOptionPane 输入验证

java - 从 Scanner 和 JOptionPane 加载的字符串之间的区别