Reputation: 163
I am trying to use Java's JOptionnPane module. Here is the code:
Object[] options = {"OK", "Cancel"};
JOptionPane.showInternalOptionDialog(null, "Your choice", "Division", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
error: JOptionPane: parentComponent does not have a valid parent at...
Upvotes: 0
Views: 536
Reputation: 109823
exception talking about uncorrectly user parameters, its value or their orders,
import java.awt.EventQueue;
import javax.swing.Icon;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
public class MyOptionPane {
public MyOptionPane() {
Icon errorIcon = UIManager.getIcon("OptionPane.errorIcon");
Object[] possibilities = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
Integer i = (Integer) JOptionPane.showOptionDialog(null,
null, "ShowInputDialog",
JOptionPane.PLAIN_MESSAGE,1, errorIcon, possibilities, 0);
Integer ii = (Integer) JOptionPane.showInputDialog(null,
"Select number:\n\from JComboBox", "ShowInputDialog",
JOptionPane.PLAIN_MESSAGE, errorIcon, possibilities, "Numbers");
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
MyOptionPane mOP = new MyOptionPane();
}
});
}
}
Upvotes: 1
Reputation: 30688
JOptionPane.showInternalInputDialog is to be used with JDesktopPane/JInternalFrames only, where this is the JDesktopPane/JInternalFrames instance.
final JDesktopPane deskpane = new JDesktopPane();
...
String str=JOptionPane.showInternalInputDialog(deskpane, "Enter value");
If not used with either of the 2 above mentioned components it will not produce the correct output, in fact it will throw a Runtime Exception:
java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid pa
Upvotes: 1