小编Jua*_*ong的帖子

使用内部对话框的JOptionPane问题

String result = JOptionPane.showInputDialog(this, temp);
Run Code Online (Sandbox Code Playgroud)

result 值将是输入的值.

String result = JOptionPane.showInternalInputDialog(this, temp);
Run Code Online (Sandbox Code Playgroud)

result 即使您输入了一个字符串,该值也将为null.

temp是一个将包含在JOptionPane中的面板.此JOptionPane将显示在另一个自定义JOptioPane之上.

java swing joptionpane

2
推荐指数
1
解决办法
4667
查看次数

相同的逻辑,但与JOptionPane和JFrame有不同的结果

代码1:

public static JFrame frame = null;    
public myClass(JFrame frame1)
{
    initComponents();
    frame = frame1;
    String result = JOptionPane.showInternalInputDialog(
        frame.getContentPane(), "Sample");
}
Run Code Online (Sandbox Code Playgroud)

代码2:

public static JFrame frame = null;
public myClass(JFrame frame1)
{
    initComponents();
    frame = frame1;
    sampleMethod();
}

public static void sampleMethod() 
{
    String result = JOptionPane.showInternalInputDialog(
        frame.getContentPane(), "Sample");
}
Run Code Online (Sandbox Code Playgroud)

我希望代码1中的结果,但代码必须看起来像代码2.为什么它们有不同的结果?

java swing joptionpane

-2
推荐指数
1
解决办法
125
查看次数

标签 统计

java ×2

joptionpane ×2

swing ×2