JOptionPane.showInternalInputDialogJDesktopPane/ JInternalFramesでのみ使用されます。ここthisで、はJDesktopPane/ JInternalFramesインスタンスです。
final JDesktopPane desk = new JDesktopPane();
...
String s=JOptionPane.showInternalInputDialog(desk, "Enter Name");
上記の2つのコンポーネントのいずれかと一緒に使用しないと、正しい出力が生成されません。実際、ランタイム例外がスローされます。
java.lang.RuntimeException:JOptionPane:parentComponentに有効な親がありません
アップデート
あなたのコメントによると、ここにあなたが追加JPanelしJDesktopPaneて呼び出す方法の例がありますJOptionPane#showInternalInputDialog。setBounds重要な部分は、追加されているかのようsetVisibleに呼び出す必要があることです。もちろん、追加している場合を除きます。JPanelJInternalFrameJDesktopPaneJPanel
JFrame frame = new JFrame("JInternalFrame Usage Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// A specialized layered pane to be used with JInternalFrames
jdpDesktop = new JDesktopPane() {
@Override
public Dimension getPreferredSize() {
return new Dimension(600, 600);
}
};
frame.setContentPane(jdpDesktop);
JPanel panel = new JPanel();
panel.setBounds(0, 0, 600, 600);
jdpDesktop.add(panel);
frame.pack();
frame.setVisible(true);
panel.setVisible(true);
String result = JOptionPane.showInternalInputDialog(jdpDesktop, "h");
System.out.println(result);