Problem wit JOptionPane.showMessageDialog

I'm not getting where is the problem here,
JTextField = AlteKarte,jtf3;
jtf3.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
public void focusLost(FocusEvent e) {
if (!e.isTemporary() && isEnabled() ) {
String Alte = AlteKarte.getText();
String FoneNum = jtf3.getText();
if (Alte.length() != 0 ){
if(Alte.equals("123") != FoneNum.equals("123")) {
JOptionPane optionPane = new JOptionPane();
int answer =((Integer)optionPane.getValue()).intValue();
JOptionPane.showMessageDialog(MainEPOS.frame,"Geben Sie bitte gultige Karten-Seriennummer an.","Fehler",JOptionPane.WARNING_MESSAGE,null);
if(answer == JOptionPane.OK_OPTION || answer == JOptionPane.CLOSED_OPTION){
jtf3.requestFocus(true);
[\code ]
i'm getting java.lang.ClassCastException at line int answer =((Integer)optionPane.getValue()).intValue();
[\code]

i have made it this way :-
         jtf3.addFocusListener(new FocusListener() {
              public void focusGained(FocusEvent e) {
              public void focusLost(FocusEvent e) {
                if (!e.isTemporary() && isEnabled() ) {
                  String Alte = AlteKarte.getText();
                  String FoneNum = jtf3.getText();
                  if (Alte.length() != 0 ){
                       if(Alte.equals("123")  != FoneNum.equals("123")) {
                   JOptionPane optionPane = new JOptionPane();
                   Object[] options = {"OK"};
                   int answer =   JOptionPane.showOptionDialog(MainEPOS.frame,"Geben Sie bitte gultige Karten-Seriennummer an.","Fehler",JOptionPane.WARNING_MESSAGE,JOptionPane.OK_OPTION, null, options, options[0]);
                 //  int answer =((Integer) optionPane.getValue()).intValue();
                   if(answer == JOptionPane.OK_OPTION || answer == JOptionPane.CLOSED_OPTION){
                        jtf3.requestFocus(true);
      });but now the problem is, that it does not get closed at once.
When i click OK then message appears again, and in second attempt it works.

Similar Messages

  • STRANGE problem with JOptionPane.showMessageDialog .. HELP!!!

    Please look at the code below and tell me what is wrong with it and my code is very very very simple!!! And I can't seem to understand why this error is coming up.
    import javax.swing.JOptionPane;
    public class ShowMessageDialog {
    public ShowMessageDialog() {
    //empty constructor for now
    public void show () {
    JOptionPane.showMessageDialog (null, "Please try again!!", "Error Message", JOptionPane.ERROR_MESSAGE);
    }This class is invoked by another class named SendPacketBack which does nothing but checks for one condition in an if statment and then make an object of this class and calls this show() method and this error comes up. Please look at the error below and tell me why it is telling me java.lang.NoClassDefFoundError and not telling me which class???
    java.lang.NoClassDefFoundError
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Class.java:141)
         at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
         at sun.awt.motif.MToolkit.<clinit>(MToolkit.java:81)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Class.java:141)
         at java.awt.Toolkit$2.run(Toolkit.java:748)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:739)
         at javax.swing.ImageIcon.<init>(ImageIcon.java:205)
         at javax.swing.LookAndFeel$1.createValue(LookAndFeel.java:274)
         at javax.swing.UIDefaults.getFromHashtable(UIDefaults.java:184)
         at javax.swing.UIDefaults.get(UIDefaults.java:129)
         at javax.swing.MultiUIDefaults.get(MultiUIDefaults.java:44)
         at javax.swing.UIDefaults.getIcon(UIDefaults.java:410)
         at javax.swing.UIManager.getIcon(UIManager.java:537)
         at javax.swing.plaf.basic.BasicOptionPaneUI.getIconForType(BasicOptionPaneUI.java:555)
         at javax.swing.plaf.basic.BasicOptionPaneUI.getIcon(BasicOptionPaneUI.java:543)
         at javax.swing.plaf.basic.BasicOptionPaneUI.createMessageArea(BasicOptionPaneUI.java:313)
         at javax.swing.plaf.basic.BasicOptionPaneUI.installComponents(BasicOptionPaneUI.java:154)
         at javax.swing.plaf.basic.BasicOptionPaneUI.installUI(BasicOptionPaneUI.java:122)
         at javax.swing.JComponent.setUI(JComponent.java:449)
         at javax.swing.JOptionPane.setUI(JOptionPane.java:1693)
         at javax.swing.JOptionPane.updateUI(JOptionPane.java:1715)
         at javax.swing.JOptionPane.<init>(JOptionPane.java:1678)
         at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:828)
         at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:642)
         at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:613)
         at cc.ShowMessageDialogue.show(ShowMessageDialogue.java:13)
         at cc.SendPacketBack.sendPacketTo(SendPacketBack.java:62)
    I would appreciate any suggestions or advice to solve this issue.
    Regards
    Khurram

    Yes X server is alright. I should have mentioned one thing though in my previous email is that there is another class which extends JFrame and is part of the package that this class is in also running in the background but that class does not interact with this class at all and does not even know if it exists!
    I don't know if that thing is causing some kind of problem which is not coming up here?
    Khurram

  • InputVerifier and JOptionPane.showMessageDialog

    Since I have intalled JDK 1.4. I have got the following Problem:
    in the verify Method there is a call to JOptionPane.showMessageDialog
    in order to show a error message if the input doesn�t match and before false is returned.
    It doesn�t work anymore with 1.4. In case of error, the message Dialog is not coming up and the verify methodis just called in a endless loop.

    try setting the InputVerifier to null before displaying the JOptionPane, then set it back after the JOptionPane.
    textField.setInputVerifier(null)
    JOptionPane.showMessageDialog(...)
    textField.setInputVerifier(this)

  • Keyboard problems with joptionpane.ShowConfirm

    hello,
    I am using show confirm dialog and there is a yes and no button with it.
    I want the software to exit when the user clicks yes button.
    the code works fine when the user uses mouse. but when I use the enter key on yes or no button, the application exits in both the cases.
    further more if I perform the same action with the space bar on the keyboard it still works fine and when I hit space bar on the no button the application stays. but with enter key the application doesn't seam to take the right yes/ no value in the integer.
    what's the problem
    and how do I correct it.
    thanks
    Krishnakant.

    import javax.swing.*;
    class Testing
       public Testing()
          try{UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");}
          catch(Exception e){e.printStackTrace();}
          int btn = JOptionPane.showConfirmDialog(null,"tab to a button, then press [ENTER]",
                                                             "",JOptionPane.YES_NO_OPTION,-1);
          String selection = "Escape (or 'x') selected";
          if(btn == 0) selection = "Selection = 'Yes'";
          else if(btn == 1)  selection = "Selection = 'No'";
          JOptionPane.showMessageDialog(null,selection);
          System.exit(0);
      public static void main(String[] args){new Testing();}
    }

  • Missing message on JOptionPane.showMessageDialog

    Hi,
    I created two JTrees and drew a line from a node in one tree to a node in another tree.
    After the mouse was released, I showed a message using JOptionPane.showMessageDialog(null, message). The message was not displayed. But if I show the message dialog box before I draw the line,
    the message is displayed.
    Could someone point me the possible problems or any similar example code?
    Thanks in advance!
    Jing

    Hi,
    First of all thanks for ur reply.I think u r not getting my point i don't want that my process waits for the JDialog to be closed.I want that my first Dialog should close automatically when my next Dialog pop up.My application requirement is i want to show two types of dialog one is when my work is going on "Please wait.." and another is when my work has beeen completed confimation message "Work has been completed".I want that when my work has beeen completed then my "Please wait.." dialog box should close automatically and confimation message dialog box should pop up.Plz guide me how i can do that.
    Regards
    Bikash

  • JOptionPane.showMessageDialog() help

    I am trying to do a search on names inwhich i input into a file and then show them on a joptionpane. My problem is that I can't get it to run b/c it says that i have incompatable types. Please help if at all possible.
    String name, custid, num, result;
    int id, element;
    public void search(){
    num = JOptionPane.showInputDialog("Enter Customer ID:");
    id = Integer.parseInt(num);
    name = tree.lookUp(id);
    result = JOptionPane.showMessageDialog(null,new JTextArea(name));
    }

    result = JOptionPane.showMessageDialog(null,new JTextArea(name));your wrong if the JOptionPane.showMessageDialog()'return type is void,it means it hasn't a return value and you want to put a value to "result",you should use like this
    JOptionPane.showMessageDialog(null,new JTextArea(name));

  • JOptionPane.showMessageDialog BLOCKS my application

    ohhhhhhhh, this one drives me crazy.
    The code below will show the message "msg: 884R, Chcek your account!" when the user log to the system.
    THE PROBLEM: say the user activate the application and recieved this message, and then he switches to a different application (e.g, IE) and returns to the application - HE DOESN'T SEE THE MESSAGE, hence, the application is BLOCKED!!! :-(
    ANYONE???!?!?!
    if (secDB.pendingUsers())
    Component c = SwingUtilities.getRoot((Component)e.getSource());
    JFrame parentFrame = (JFrame)c;                              JOptionPane.showMessageDialog(parentFrame, "msg: 884R, Chcek your account!");
    }

    It works for meimport java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test3 extends JFrame {
      public Test3() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        JButton jb = new JButton("Show Optionpane");
        content.add(jb, BorderLayout.SOUTH);
        jb.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            JOptionPane.showMessageDialog(SwingUtilities.getRoot((Component)ae.getSource()),
                                          "This is a message");
        setSize(300,300);
        setVisible(true);
      public static void main(String[] args) { new Test3(); }
    }

  • JOptionPane.showMessageDialog blinks first at upper left corner

    Hello everybody,
    I am facing the following problem using SWING 1.1.1 (sorry but I need to use this old guy): When I invoke a dialog by using JOptionPane.showMessageDialog the dialog first blinks at the upper left corner of the parent window and after it appears correctly at the center.
    This happens very quickly, but it is really annoying ! Can someone help me ?
    Thanks in advance.

    it's rather bad because old version swing is used very rarely now. and I do not see
    this bug in later version swing.

  • Passing formatted HTML into JOptionPane.showMessageDialog()

    I'm attempting to display a message dialog that contains text that is formatted as HTML. The examples I've looked up online show that you can indeed create a string that begins with the tag <html> and pass that string into most swing text components.
    Such as:
    String htmlString = "<html><b>This is a bold string</b>";
    JOptionPane.showMessageDialog(htmlString, ...);I want to do the same thing, but have my HTML stored in a seperate file. I tried using file IO to read in the html one line at a time, and append it into a StringBuffer. Then passing my buffer.toString() into showMessageDialog(). ..It's still not showing my HTML (although it does compile fine).
    Before I start digging into this deep, I just wanted to ask if there was a better solution for accomplishing what I'm trying to do here. Perhaps using a different component or something? I appreciate it.

    (shrugs) Both these examples seem to render the HTML OK, the first is a String provided to a JLabel, the second is an URL provided to a JEditorPane. I included the second to show a Swing component rendering HTML from an external source.
    import java.awt.Dimension;
    import javax.swing.JOptionPane;
    import javax.swing.JEditorPane;
    import java.net.URL;
    class TestHtmlRendering {
      public static void main(String[] args) throws Exception {
        // default for a String in a JLabel is bold,
        // so let's add some emphasis..
        String content =
          "<html><b>This is a bold, " +
          "<em>emphatic</em> string!</b>";
        JOptionPane.showMessageDialog(null, content);
        // styled HTML from http://pscode.org/test/docload/
        URL url = new URL(
          "http://pscode.org/test/docload/trusted.html");
        JEditorPane jep = new JEditorPane(url);
        jep.setPreferredSize(new Dimension(300,200));
        JOptionPane.showMessageDialog(null, jep);
    }I'd say the problem is in the code you did not show, though even the code you did show, was nonsense (show me the URL to the JavaDocs of any showMessageDialog() method that will accept a String as the first argument). For those reasons (and more), I recommend preparing an SSCCE that shows the problem. It is a little harder to prepare an SSCCE involving external files, though if you can demonstrate it using an URL (like above) that solves the problem.

  • How to remove 1797 emails. stuck in inbox.  but not showing anymore - and i have the same problem wit the sent.  please help

    how to remove 1797 emails. stuck in inbox.  but not showing anymore - and i have the same problem wit the sent.  please help

    This is a user supported frum, so making threats really doesn't help, besides which it's not like any of us can really make a dent in Toshiba's bottom line despite how many people we think we can influence. Unless those people were standing in line to buy a Toshiba product cash in hand, and you pulled them out, it really doesn't add up for them.
    At this point it would probably be better for you to use the 800 number. Have all your e-mails ready to forward, if needed, to whoever you end up talking to. Don;t let them off the hook. An hour on the phone is much better than weeks passing e-mails through a support site. Also contest the charge with your bank or credit card.

  • JOptionPane.showMessageDialog() - word wrapping exceptions?!

    Hey ppl,
    Probably a silly question...
    I'm currently working with JDBC, and SQLexceptions can be very long! Currently displaying them in a JOptionPane.showMessageDialog() (as i guess most people do?), but being so long they cause it to span the whole screen & then some!
    I looked through the JOptionPane API, but didn't spot anything that might help. Is there a way to get this exception to dispaly on multiple lines, kinda like word wrap in notepad?
    Cheers for any suggestions.
    Jim

    I can't speak for other developers..But as for myself, I rarely if ever print error messages to the JOptionPane. Almost always, I print my error messages and the stack if necessary, to the ouput. This is either a command line window, console, log file, or output screen in an ide depending upon how you program. My code looks something like this.
    catch(Exception e)
        System.out.println(e.getMessage());  // Will print only the message property of the exception
        e.printStackTrace();  // Will print the stack for more information
    }Sorry I couldn't answer your question directly. Maybe someone else can. Hope I was helpful anyway.

  • Change Button Name in JOptionPane.showMessageDialog

    Hello,
    I've written the following code that invokes a JOPtionPane messageDialog, when the delete button is hit in the following frame and the selectedItem in the JComboBox is Default.
    I want to change the JOPtionPane button name from OK to Close. Is there a way to do this with error message dialoges, as their is with confirmDialoges?
    Please help out.
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    public class MyJOptionPaneTest {
         public MyJOptionPaneTest()
              JFrame frame = new JFrame("My Frame");
              JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT,5,0));
              final JComboBox myComboBox = new JComboBox();
              myComboBox.setPreferredSize(new Dimension(100,20));
              myComboBox.getModel().setSelectedItem("Default");
              myComboBox.addItem("Default");
              myComboBox.addItem("Other");
              JButton deleteButton = new JButton("Delete");
              deleteButton.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        if(myComboBox.getSelectedItem().equals("Default"))
                             JOptionPane.showMessageDialog(null, "Default cannot be deleted", "Error", JOptionPane.ERROR_MESSAGE);
              panel.add(myComboBox);
              panel.add(deleteButton);
              frame.getContentPane().add(panel);
              frame.setSize(200,100);
              frame.setResizable(false);
              frame.setVisible(true);
         public static void main(String [] args)
              MyJOptionPaneTest test = new MyJOptionPaneTest();
    }

    Hi,
    yes, I've looked at the tutorials. But there is no way to change button title for JOptionPane.showMessageDialog. Only JOptionPane.showOptionsDialog provides you w/ that feature, becuz it provides the parameter in the method.
    I was wondering if there was another way to do this for showMessageDialog.

  • JOptionPane.showMessageDialog vs JOptionPane.showInternalMessageDialog

    This is my first post to the message boards, so please don't be too hard on me if this is really obvious...
    I'm trying to show a pop-up box with a message to indicate an error to the user; the JOptionPane.showMessageDialog works just fine, however when I use JOptionPane.showInternalMessageDialog, I get a NullPointerException being thrown by the L&F component(s) as follows (I'm currently running this as an applet via appletviewer):
    Exception occurred during event dispatching:
    java.lang.NullPointerException
    at javax.swing.plaf.metal.MetalLookAndFeel.getPrimaryControlDarkShadow(MetalLookAndFeel.java:1083)
    at javax.swing.plaf.metal.MetalBorders$OptionDialogBorder.paintBorder(MetalBorders.java:188)
    at javax.swing.JComponent.paintBorder(JComponent.java:574)
    at javax.swing.JComponent.paint(JComponent.java:740)
    at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:23)
    at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:54)
    at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:91)
    at java.awt.Container.paint(Container.java:960)
    at java.awt.Container.update(Container.java:981)
    at sun.awt.RepaintArea.update(RepaintArea.java:337)
    at sun.awt.motif.MComponentPeer.handleEvent(MComponentPeer.java:404)
    at java.awt.Component.dispatchEventImpl(Component.java:2722)
    at java.awt.Container.dispatchEventImpl(Container.java:1214)
    at java.awt.Component.dispatchEvent(Component.java:2556)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:333)
    at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)
    I guess that I've really got two questions about this whole thing... 1) What could be causing the NullPointerException and 2) What is the real difference between JOptionPane.showMessageDialog and JOptionPane.showInternalMessageDialog?

    Here's the call that I'm using to the function -- sorry for not posting that originally...
    JOptionPane.showInternalMessageDialog( this, getString( "Messages.NoPOsSelected" ), "Error", JOptionPane.ERROR_MESSAGE );Where "this" should be the applet itself, since this is being called from a function within the JApplet.

  • JOptionPane.showMessageDialog auto closed by itself

    Hi guys,
    I"m facing a very weird issue. Our application is written in Swing and we encounter that the JOptionPane is automatically closed.
    <code>
    logger.debug( "Showing message dialog" );
    JOptionPane.showMessageDialog( this,
    "Some message" );
    logger.debug( "Message dialog returned" );
    </code>
    In the logs we have found out that it printed both directly. The user didn't have the chance to click OK button.
    We are using JDK 1.5.0_15, Windows XP Pro SP2
    Thanks.

    You need to create a "Short, Self Contained, Compilable
    and Executable, Example Program (SSCCE)",
    see http://homepage1.nifty.com/algafield/sscce.html,
    that demonstrates the incorrect behaviour, because I can't
    guess exactly what you are doing based on the information provided.
    Don't forget to use the "Code Formatting Tags",
    see http://forum.java.sun.com/help.jspa?sec=formatting,
    so the posted code retains its original formatting.

  • JOptionPane.showMessageDialog ( ERROR_MESSAGE)

    hi can anyone help...
    i am using a
    JOptionPane.showMessageDialog ( ERROR_MESSAGE)
    to validate my input in some textfields... and when
    there is an ERROR the merror message will pop up...
    how to write the code so that when the user click the
    OK button inside the pop-up msg , the button can
    handle some functions as to reset some variable....??

    If you read the javadocs for JOptionPane you will find that the dialog you get from calling any JOptionPane.showXXXDialog method is modal. Consequently, when you have called showMessageDialog the current thread will be blocked until the user presses the OK button. So you can just put your reset handling code after the call to showMessageDialog, like the following little program demonstrates:
    import java.awt.event.*;
    import javax.swing.*;
    public class OptionPaneErrorTest {
        public static void main(String[] args) {
            ApplicationFrame app = new ApplicationFrame();
            app.setVisible(true);
        private static class ApplicationFrame extends JFrame {
            public ApplicationFrame() {
                JButton btn = new JButton("Click Me");
                btn.addActionListener( new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        JOptionPane.showMessageDialog(null, "This is an error message", "Error", JOptionPane.ERROR_MESSAGE);
                        System.out.println("This will get printed when the user presses the OK button");
                getContentPane().add(btn);
                pack();
    }Hope this helps.

Maybe you are looking for