我可以以非模态方式使用Java JOptionPane吗? [英] Can I use a Java JOptionPane in a non-modal way?

查看:233
本文介绍了我可以以非模态方式使用Java JOptionPane吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,当某个动作发生时弹出一个JOptionPane。我只是想知道当JOptionPane确实弹出时你怎么可能仍然使用后台应用程序。目前,当JOptionPane弹出时,我关闭JOptionPane之前无法执行任何其他操作。

I am working on an application which pops up a JOptionPane when a certain action happens. I was just wondering if it was possible that when the JOptionPane does pop up how can you still use the background applications. Currently when the JOptionPane pops up I can't do anything else until I close the JOptionPane.

编辑

感谢回复人员和信息。认为生病了将此功能从应用程序中删除,因为它看起来可能比必要的更麻烦。

Thanks for the reply guys and the information. Think ill leave this function out of the application cause it looks like it could be more hassle than necessary.

推荐答案

文档明确指出所有对话框都是模态的,当通过showXXXDialog方法创建时。

The documentation explicitly states that all dialogs are modal when created through the showXXXDialog methods.

您可以使用的是从文档中获取的直接使用方法以及 setModal 方法:

What you can use is the Direct Use method taken from the docs and the setModal method that JDialog inherits from 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 JOptionPane吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆