gpt4 book ai didi

java - 使用 Java 的 JOptionPane

转载 作者:行者123 更新时间:2023-12-02 06:39:25 24 4
gpt4 key购买 nike

我正在尝试使用 Java 的 JOptionnPane 模块。这是代码:

Object[] options = {"OK", "Cancel"};
JOptionPane.showInternalOptionDialog(null, "Your choice", "Division", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);

错误:JOptionPane:parentComponent 在...处没有有效的父组件

最佳答案

JOptionPane.showInternalInputDialog 仅与 JDesktopPane/JInternalFrames 一起使用,这是 JDesktopPane/JInternalFrames 实例。

final JDesktopPane deskpane = new JDesktopPane();
...
String str=JOptionPane.showInternalInputDialog(deskpane, "Enter value");

如果不与上述两个组件一起使用,它将不会产生正确的输出,实际上它会抛出运行时异常:

java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid pa

关于java - 使用 Java 的 JOptionPane,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19292460/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com