Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JOptionPane problems

0 views
Skip to first unread message

Kirk Abbott

unread,
Feb 15, 1998, 3:00:00 AM2/15/98
to

Hello,
I am trying to pop up some inputdialog boxes and I am trying
to use JOptionPane to doit. There are a number static methods
in JOptionPane such as:

1) public static String showInputDialog(Object message);
2) public static String showInputDialog(Component parentComponent,
Object message);
3) public static String showInputDialog(Component parentComponent,
Object message,
String title,
int messageType);
etc..
When I use the (1) it does not work at all... complaining about

java.lang.IllegalArgumentException: null parent frame
at java.awt.Window.<init>(Window.java:86)
at java.awt.Dialog.<init>(Dialog.java:107)
at com.sun.java.swing.JDialog.<init>(JDialog.java:87)

When I use (2) or (3) and attempt to give a parent *frame* using
some getFrame() code that recursively calls get getParent(),
it shows the dialog and accepts the input *but* gives throws
the following exception:

Exception occurred during event dispatching:
java.lang.NullPointerException:
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:1416)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:133

which is just ugly as anything.
Does anyone know what is causing the problem ? Does anyone know
what the true purpose of the parentComponent arg is ?

I am attaching the smallest some code that I could find that replicates
the problem under linux and nt. It shows a frame with a button.
Double clicking on the button pops up a dialog box, then look out
for the exception....

Cheers and thanks,
Kirk.

//--------------------------save to TestOptionPane.java---------------
import java.awt.*;
import java.awt.event.*;
import java.awt.Dimension;
import java.io.*;
import java.util.*;

import com.sun.java.swing.*;
import com.sun.java.swing.border.*;
import com.sun.java.swing.event.*;
import com.sun.java.swing.text.*;

public class TestOptionPane extends JPanel
{

public TestOptionPane()
{
super();
setDoubleBuffered(true);
setLayout(new BorderLayout());
JButton b = new JButton("cat");
add("North", b);
b.addMouseListener(new MouseListener());
}

public void doit()
{
String newPath = (String)
JOptionPane.showInputDialog(getFrame(), /*** ?????? ****/
"Enter path",
null,
JOptionPane.PLAIN_MESSAGE,
null, /* icon */
null, /* selectionValues[] */
"/usr2/tmp");
}

protected Frame getFrame()
{
for (Container p = getParent(); p != null; p = p.getParent()) {
if (p instanceof Frame) {
return (Frame) p;
}
}
return null;
}

class MouseListener extends MouseAdapter
{

public void mouseClicked(MouseEvent e)
{
System.out.println("Mouse clicked");
if (e.getClickCount() == 2) {
doit();
}
}

public void mousePressed(MouseEvent e)
{
System.out.println("Mouse pressed");
}

public void mouseReleased(MouseEvent e)
{
System.out.println("Mouse released");
}
}

/**
* Our WindowListener class
*/
protected static final class AppCloser extends WindowAdapter
{
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}

public static void main(String args[])
{
JFrame frame = new JFrame();

frame.setTitle("Test JOptionPane");
frame.setBackground(Color.lightGray);
frame.getContentPane().setLayout(new BorderLayout());

TestOptionPane t = new TestOptionPane();

frame.getContentPane().add("North", t);
frame.addWindowListener(new AppCloser()); // to shut down
frame.setSize(300, 300);
frame.pack();
frame.show();

}

}

0 new messages