我正在开发一个应用程序,它会在发生特定操作时弹出 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/