JOptionPane.showOptionDialog(..) -problem

Hi!
I'm trying to ask the size of area of game with OptionDialog. Then this
code should open the game frame. But the OptionDialog doesn't react
to clicking. (doesn't close). Could you find the errorpoint?
I have trying to find it many days.
Could it be probably so that the main-method can't open frame after frame (first optionDialog then gameframe)?
Gameframe opens when I test it to replace getGameAreaSize()-method simply with:
public int getGameAreaSize() {
return 10;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class BattleShipGame {
     private int gameAreaSize;
     private Gameframe gameFrame;
     public Gameframe getGameframe() {
        if (gameFrame == null) {
             gameFrame = new Gameframe();
             gameFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        return gameFrame;
     public int getGameAreaSize() {
       Object[] options = {"10 x 10",
                           "12 x 12",
                           "14 x 14"};
       int n = JOptionPane.showOptionDialog(new Frame(),
       "Choose the area of the game: ",
       "question about area",
        JOptionPane.YES_NO_CANCEL_OPTION,
        JOptionPane.QUESTION_MESSAGE,
        null,
        options,
        options[2]);
        if (n==0) return (gameAreaSize = 10);
        if (n==1) return (gameAreaSize = 12);
        if (n==2) return (gameAreaSize = 14);
        else return (gameAreaSize = 0);
     public static void main(String[] args) {
        BattleShipGame bsg = new BattleShipGame();
        int size = bsg.getGameAreaSize();
        Gameframe gameframe = bsg.getGameframe();
        gameframe.setVisible(true);

int n = JOptionPane.showOptionDialog(new Frame(),
should be :
int n = JOptionPane.showOptionDialog(this,
Because when you start a new frame that hasn't got the focus and you let that frame pop the optionpane the mouse listener andsoon isn't listening to the optionpane.

Similar Messages

  • A question about JOptionPane.showOptionDialog()?

    one problem confused me.
    import javax.swing.*;
    class Test
    public Test()
         int n;
         String title;
         Object[] message = new Object[3];
         Object[] obj = new Object[2];
         message[0] = "Name ";
         message[1] = "Age";
         title = "Information";
         obj[0] = "OK";
         obj[1] = "Cancel";
         n = JOptionPane.showOptionDialog(null,
         message,
         title,
    JOptionPane.OK_CANCEL_OPTION,
              JOptionPane.INFORMATION_MESSAGE,
                        null,
                        obj,
                        obj[0]);               
         public static void main(String[] args)
              new Test();
    i run the java compiler in command line.
    c:\proj1>javac Test.java
    c:\proj1>java Test
    Having done the program, i found that command line didnot return to "c:\proj1>"
    only after "Ctrl-c" can that return back to the "c:\proj1". i didnot meet this problem when i run other java projects.
    what's the problem?
    thanks!

    Implement a call to System.exit(0) at the point you want the programm to close.
    (Depending on the return code of your option dialog)

  • Simple JOptionPane.showOptionDialog() question

    Could you please help me:
    Here's a piece of code:
    JPasswordField field = new JPasswordField();
    int choice = JOptionPane.showOptionDialog(null, field, "Enter password:", 0,
    JOptionPane.QUESTION_MESSAGE, null,
    new String[] {"ОК", "Cancel"}
    , null);
    How to make an enter-key-press on JPasswordField to be equivalent to pressing OK key?? If it's possible or i should use bigger constructions (like private class PasswordAskClass extends JDialog) ???
    Thanks in advance for your replies.

    The problem is that you don't have a reference to the OK button.
    1) use a JDialog like you suggest.
    2) Create the buttons yourself, and pass them into JOptionPane as arguments.
    Then you'll be able to add a KeyMap to your JPasswordField that when ENTER is pressed, it sends an action event to your OK button.

  • Change the initial focus to "message" in JOptionPane.showOptionDialog?

    JPanel panel = new JPanel (false);
    JTextArea txtArea = new JTextArea (msg, 2, 60);
    JScrollPane sPane = new JScrollPane (txtArea);
    panel.add (sPane);
    int button = JOptionPane.showOptionDialog (frame, panel, titleStr, optionType, JOptionPane.PLAIN_MESSAGE, null, null, null);
    Is there a way to make txtArea to have the initial focus?
    Thanks,
    Ben

    Hi,
    Check out this post:
    Hide the 'no data found' message
    I hope that helps.
    -Marc

  • JOptionpane.showOptionDialog help

    Object[] options = {"YES", "NO"};
    JOptionPane.showOptionDialog (null, "Are you sure you want to leave", "Warning",
    JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
    null, options, options [0]
    there is the code now i cant figure out a way to make the program exit if you say yes.. i know how stupid of me can some one plz help me?
    should i write a if with a system.exit or what?

    Swing related questions should be posted in the Swing forum.
    Search the forum before posting a questions
    Here is a simple example found in the Swing forum:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=695964

  • JOptionPane blocking problem

    I have the following code in my 1.4.1 applet:
    int response = JOptionPane.showConfirmDialog(NewJabber.mainFrame,"Receive message from unregistered user: "+jid.getName()+" over the "+JID.SHOWNAMES[jid.getHostType()]+" transport. Accept and add user to roster?","Message Received",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
    if(response == JOptionPane.YES_OPTION){
    The dialog seems to work like a charm, but after it's been open for about 3 seconds, it somehow enters an infinite loop because IE starts to use 100% of my processor. I don't want users to have their computer DRASTICALLY slow until they respond to the dialog.(which does work and stops the processor usage)
    this only seems to be a problem with showConfirmDialog(). The following code works fine and so do my classes that extend JDialog.
    public static String getInput(String show){
    return JOptionPane.showInputDialog(show);
    }

    I assume you mean: JOptionPane.showConfirmDialog(this, ...)
    problem is that 'this' isn't a Component.

  • JOptionPane showConfirmDialog problem

    Hello everyone,
    I have written my own class that shows a customized confirm dialog (code is pasted below). I need to be able to tell whether the user clicks "YES", "NO" or "CANCEL".
    My main app has a panel with a JButton "Start System". When this button is clicked, the following code instantiates OperatorConfirmDialog:
         public void startNetwork(){
              confirmDialog = new OperatorConfirmDialog("Are you sure you want to start the network?");
              System.out.println("WE MADE IT TO HERE");//problem we do not get to here until confirm dialog acked
         }I referred to the examples for JOptionPane given at:
    http://java.sun.com/j2se/1.5.0/docs/api/index.html
    for examples but it doesn't seem to be working for me.
    Here is the code for OperatorConfirmDialog
    public class OperatorConfirmDialog extends JFrame {
         JOptionPane pane;
         public OperatorConfirmDialog(String message){
              pane = new JOptionPane();
              this.setDefaultLookAndFeelDecorated(true);
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              this.getContentPane().setLayout(new BorderLayout());
              pack();
              //pane.getSelectionValues()
              pane.showConfirmDialog(this, message, "Confirm", JOptionPane.YES_NO_CANCEL_OPTION);
              Object selectedValue = pane.getValue();  //problem here
              if(selectedValue == null){
                   //do nothing...they just killed window
              }else {
                   for(int counter = 0, maxCounter = pane.getOptions().length; counter < maxCounter; counter++){
                        if(pane.getOptions()[counter].equals(selectedValue)){
                             //do something
              this.dispose();
         public JOptionPane getPane(){
              return pane;
         public static void main(String[] args) {
              OperatorConfirmDialog dialog = new OperatorConfirmDialog("Please enter a valid username.");
    }I put a break point at the line:
    if(selectedValue == null){
    When I run the debugger, confirmDialog prompts me to click "YES", "NO" or "CANCEL". I click "YES" and then arrive at the breakpoint. But, selectedValue doesn't seem to have the right value....the debugger says its value is "uninitializedValue" (literally). Any ideas?
    Thanks!

    Try this. Notice I received an int result from the showConfirmDialog() method.
    import javax.swing.*;
    import java.awt.*;
    public class OperatorConfirmDialog extends JFrame {
        JOptionPane pane;
        public OperatorConfirmDialog(String message) {
            pane = new JOptionPane();
            this.setDefaultLookAndFeelDecorated(true);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.getContentPane().setLayout(new BorderLayout());
            pack();
    // get the response from the user
            int result = pane.showConfirmDialog(this, message, "Confirm", JOptionPane.YES_NO_CANCEL_OPTION);
            if (JOptionPane.YES_OPTION == result) {
                // do what you want on 'yes' clicked
                System.out.println("User Clicked 'Yes'.");
            } else {
    // user clicked 'no' or 'cancel'... you could check result for JOptionPane.NO_OPTION or CANCEL_OPTION
                System.out.println("User Clicked either 'No' or 'Cancel'.");
            this.dispose();
        public JOptionPane getPane() {
            return pane;
        public static void main(String[] args) {
            OperatorConfirmDialog dialog = new OperatorConfirmDialog("Please enter a valid username.");
    }

  • JOptionPane handling problem

    Hi all,
    I'm imlementing a GUI using JPanel and paintComponent(Graphics g).
    When i have to display some data on the screen i use JOptionPane.showMessageDialog(...) and the data are displayed.
    The problem is that, when i close the Message Dialog, it doesn't completely disappear from the screen and so my screen is being messed up. I think it has to do with the graphic environment but i can't figure out what exactly is the problem.
    Thanks,
    John.

    I'm imlementing a GUI using JPanel and
    paintComponent(Graphics g).
    When i have to display some data on the screen i use
    JOptionPane.showMessageDialog(...) and the data are
    displayed.hello John,
    are you invoking JPanel's paintComponent ?public void paintComponent(Graphics g)
          super.paintComponent(g);
          //your painting stuff...
    }Not calling JPanel's paintComponent can cause background-painting problems.
    regards,
    Tim

  • JOptionpane listener problem

    I have a JOption pane in a dialog and it has custom text in 2 buttons, how can I put a listener on the buttons, or how do I make something happen when a button is pressed?

    Why can't you use JOptionPane but just supply 2
    strings for the "Yes" and "No" options so you canhave
    your custom text instead of supplying buttons andthen
    attaching actionListeners?
    Selection of the "Yes" option would return
    JOptionPane.YES_OPTION and "No" would return
    JOptionPane.NO_OPTION
    You can then go away and do whatever you want basedon
    the value returned through some if (...)
    statements....
    Some more info about the dialogs
    http://java.sun.com/docs/books/tutorial/uiswing/compone
    ts/dialog.htmlI am not sure how we can get the value if the button
    is selected..any how even if it is possible...how to
    perform a different function..like i rename ok to
    "Help" and if a user presses help i don't want to
    close the dialog..i just want to show some thing
    (assume)...and other button is cancel which closes the
    dialog(default behaviour)..how to achieve this help
    Thanks,
    JanaExactly what I was trying to figure out but I guess we could use the method that just creates a button and attatches an actionlistener.

  • JOptionPane/TextArea problem

    I need to get the string value from a JOptionPane and store it into a AWT TextArea.
         // Button Input
         public void actionPerformed(ActionEvent e)
              String str = e.getActionCommand();
              if (str.equals("Click Me"))
                   String inputValue = JOptionPane.showInputDialog("Please input a value");
                   txtOutput.setText(inputValue);
         }When I click OK on the JOptionPane, a NullPointerException occurs with additional text: "Exception in thread "AWT-EventQueue-1"". The text isn't added onto the text area. What am I doing wrong?

    did you declare and initalize the txtOutput variable?
    NullPointerException sometimes occur when you are trying to use operations on a null object.

  • Problem in Displaying JOptionpane Message Dialog (JRE 1.5.0_04 or later)

    Hi! All,
    I am getting a deadlock kind a situation while displaying JOptionpane message dialog. It's very rare to simulate also. I am also posting the Thread dump which i have taken programmatically, when this situation arises.
    For your Information, I am using JRE 1.5.0_04 or later version on Windows XP.
    We searched on Java.sun.com site, & we got that two bugs are related to our problem, but there are arises in JRE 1.4.2 or before version & have been fixed at JRE 1.5 .
    Follwing are the bugs ID in Sun Bugs Database: 4978089, 4828019.
    Can anyone suggest me which is the stable JRE 1.5 version to avoid this problem. Also can anyone suggest me the workaround of this problem. I want to fix this in our application ASAP.
    following is My Thread Dump :
    Thread[Finalizer,8,system]
         java.lang.Object.wait(Native Method)
         java.lang.ref.ReferenceQueue.remove(Unknown Source)
         java.lang.ref.ReferenceQueue.remove(Unknown Source)
         java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)
    Thread[Java2D Disposer,10,javawsApplicationThreadGroup]
         java.lang.Object.wait(Native Method)
         java.lang.ref.ReferenceQueue.remove(Unknown Source)
         java.lang.ref.ReferenceQueue.remove(Unknown Source)
         sun.java2d.Disposer.run(Unknown Source)
         java.lang.Thread.run(Unknown Source)
    Thread[JCIL_Sess(813251)_EvtThd(24880015),5,main]
         java.lang.Object.wait(Native Method)
         java.lang.Object.wait(Unknown Source)
         java.awt.EventQueue.invokeAndWait(Unknown Source)
         javax.swing.SwingUtilities.invokeAndWait(Unknown Source)
         in.co.netsol.telecom.desktop.CallAppearanceTable$EventAdapter.OnCallEstablished(CallAppearanceTable.java:982)
         in.co.netsol.telecom.ctios.events.EventSinkAdapter.OnEvent(EventSinkAdapter.java:142)
         com.cisco.cti.ctios.cil.EventPublisher.PostEvent(EventPublisher.java:175)
         com.cisco.cti.ctios.cil.EventPublisher.FireEvent(EventPublisher.java:142)
         com.cisco.cti.ctios.cil.CtiOsSession.FireEvent(CtiOsSession.java:1849)
         com.cisco.cti.ctios.cil.Call.FireEvent(Call.java:254)
         com.cisco.cti.ctios.cil.Call.OnCallEstablishedEvent(Call.java:1136)
         com.cisco.cti.ctios.cil.Call.OnEvent(Call.java:943)
         com.cisco.cti.ctios.cil.CtiOsSession.OnEvent(CtiOsSession.java:2107)
         com.cisco.cti.ctios.cil.CilServiceEvent.ReceiverThread(CilServiceEvent.java:256)
         com.cisco.cti.ctios.cil.CilServiceEvent$1.run(CilServiceEvent.java:173)
    Thread[pool-1-thread-5,5,main]
         java.lang.Object.wait(Native Method)
         java.lang.Object.wait(Unknown Source)
         java.awt.EventQueue.invokeAndWait(Unknown Source)
         javax.swing.SwingUtilities.invokeAndWait(Unknown Source)
         in.co.netsol.telecom.desktop.command.MakeAgentReadyCommand$EventAdapter$1.run(MakeAgentReadyCommand.java:190)
         java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
         java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
         java.lang.Thread.run(Unknown Source)
    Thread[DestroyJavaVM,5,main]
    Thread[AWT-Shutdown,5,javawsApplicationThreadGroup]
         java.lang.Object.wait(Native Method)
         java.lang.Object.wait(Unknown Source)
         sun.awt.AWTAutoShutdown.run(Unknown Source)
         java.lang.Thread.run(Unknown Source)
    Thread[JCIL_Conn(18096534)_Watchdog,5,main]
         java.lang.Object.wait(Native Method)
         com.cisco.cti.ctios.util.UnNamedEvent.WaitForSingleObject(UnNamedEvent.java:147)
         com.cisco.cti.ctios.cil.CilConnection.WatchdogThread(CilConnection.java:527)
         com.cisco.cti.ctios.cil.CilConnection$1.run(CilConnection.java:1071)
    Thread[AWT-EventQueue-0,6,main]
         java.awt.Container.getComponents_NoClientCode(Unknown Source)
         java.awt.Container.getComponents(Unknown Source)
         javax.swing.JToolBar.getComponentAtIndex(Unknown Source)
         javax.swing.plaf.basic.BasicToolBarUI.navigateFocusedComp(Unknown Source)
         javax.swing.plaf.basic.BasicToolBarUI$Actions.actionPerformed(Unknown Source)
         javax.swing.SwingUtilities.notifyAction(Unknown Source)
         javax.swing.JComponent.processKeyBinding(Unknown Source)
         javax.swing.JComponent.processKeyBindings(Unknown Source)
         javax.swing.SwingUtilities.processKeyBindings(Unknown Source)
         javax.swing.UIManager$2.postProcessKeyEvent(Unknown Source)
         java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
         java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
         java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
         java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
         java.awt.Component.dispatchEventImpl(Unknown Source)
         java.awt.Container.dispatchEventImpl(Unknown Source)
         java.awt.Window.dispatchEventImpl(Unknown Source)
         java.awt.Component.dispatchEvent(Unknown Source)
         java.awt.EventQueue.dispatchEvent(Unknown Source)
         java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         java.awt.EventDispatchThread.run(Unknown Source)
    Thread[AWT-Windows,6,main]
         sun.awt.windows.WToolkit.eventLoop(Native Method)
         sun.awt.windows.WToolkit.run(Unknown Source)
         java.lang.Thread.run(Unknown Source)
    Thread[Timer-0,5,javawsApplicationThreadGroup]
         java.lang.Thread.dumpThreads(Native Method)
         java.lang.Thread.getAllStackTraces(Unknown Source)
         in.co.netsol.telecom.log.ThreadDumpLoggingTask.getStackTraces(ThreadDumpLoggingTask.java:47)
         in.co.netsol.telecom.log.ThreadDumpLoggingTask.run(ThreadDumpLoggingTask.java:36)
         java.util.TimerThread.mainLoop(Unknown Source)
         java.util.TimerThread.run(Unknown Source)
    Thread[JCIL_Conn(18096534)_Rcvr,5,main]
         java.net.SocketInputStream.socketRead0(Native Method)
         java.net.SocketInputStream.read(Unknown Source)
         com.cisco.cti.ctios.cil.NetPort.ReceiveData(NetPort.java:405)
         com.cisco.cti.ctios.cil.NetPort.ReceiveData(NetPort.java:363)
         com.cisco.cti.ctios.cil.CilPacket.ReadFromPort(CilPacket.java:649)
         com.cisco.cti.ctios.cil.CilConnection.ReadPacket(CilConnection.java:670)
         com.cisco.cti.ctios.cil.Connection.ReceiverThread(Connection.java:398)
         com.cisco.cti.ctios.cil.Connection$1.run(Connection.java:472)
    Thread[pool-1-thread-2,5,main]
         java.lang.Object.wait(Native Method)
         java.lang.Object.wait(Unknown Source)
         java.awt.EventQueue.invokeAndWait(Unknown Source)
         javax.swing.SwingUtilities.invokeAndWait(Unknown Source)
         in.co.netsol.telecom.desktop.command.SupervisorAssistCommand$EventAdapter$1.run(SupervisorAssistCommand.java:152)
         java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
         java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
         java.lang.Thread.run(Unknown Source)
    Thread[pool-1-thread-1,5,main]
         java.lang.Object.wait(Native Method)
         java.lang.Object.wait(Unknown Source)
         java.awt.EventQueue.invokeAndWait(Unknown Source)
         javax.swing.SwingUtilities.invokeAndWait(Unknown Source)
         in.co.netsol.telecom.desktop.command.ConferenceCallCommand$EventAdapter$1.run(ConferenceCallCommand.java:144)
         java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
         java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
         java.lang.Thread.run(Unknown Source)
    Thread[JCIL_Svc(5450181)_TxQThd(3083604),5,main]
         java.lang.Object.wait(Native Method)
         java.lang.Object.wait(Unknown Source)
         com.cisco.cti.ctios.util.QueueThread.GetQItem(QueueThread.java:152)
         com.cisco.cti.ctios.util.QueueThread.run(QueueThread.java:259)
    Thread[pool-2-thread-1,5,main]
         java.lang.Object.wait(Native Method)
         java.lang.Object.wait(Unknown Source)
         java.awt.Dialog.show(Unknown Source)
         javax.swing.JOptionPane.showOptionDialog(Unknown Source)
         javax.swing.JOptionPane.showMessageDialog(Unknown Source)
         javax.swing.JOptionPane.showMessageDialog(Unknown Source)
         in.co.netsol.telecom.desktop.DesktopMainPanel$3.run(DesktopMainPanel.java:1871)
         java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
         java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
         java.lang.Thread.run(Unknown Source)
    Thread[Signal Dispatcher,9,system]
    Thread[Reference Handler,10,system]
         java.lang.Object.wait(Native Method)
         java.lang.Object.wait(Unknown Source)
         java.lang.ref.Reference$ReferenceHandler.run(Unknown Source)
    Thread[TimerQueue,5,javawsApplicationThreadGroup]
         java.lang.Object.wait(Native Method)
         javax.swing.TimerQueue.run(Unknown Source)
         java.lang.Thread.run(Unknown Source)
    Thread[pool-1-thread-4,5,main]
         java.lang.Object.wait(Native Method)
         java.lang.Object.wait(Unknown Source)
         java.awt.EventQueue.invokeAndWait(Unknown Source)
         javax.swing.SwingUtilities.invokeAndWait(Unknown Source)
         in.co.netsol.telecom.desktop.command.MakeAgentNotReadyCommand$EventAdapter$1.run(MakeAgentNotReadyCommand.java:146)
         java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
         java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
         java.lang.Thread.run(Unknown Source)
    Thread[pool-1-thread-6,5,main]
         java.lang.Object.wait(Native Method)
         java.lang.Object.wait(Unknown Source)
         java.awt.EventQueue.invokeAndWait(Unknown Source)
         javax.swing.SwingUtilities.invokeAndWait(Unknown Source)
         in.co.netsol.telecom.desktop.command.TransferCallCommand$EventAdapter$1.run(TransferCallCommand.java:136)
         java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
         java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
         java.lang.Thread.run(Unknown Source)
    Thread[traceMsgQueueThread,5,main]
         java.lang.Object.wait(Native Method)
         java.lang.Object.wait(Unknown Source)
         com.sun.deploy.util.Trace$TraceMsgQueueChecker.run(Unknown Source)
         java.lang.Thread.run(Unknown Source)
    Thread[pool-1-thread-3,5,main]
         java.lang.Object.wait(Native Method)
         java.lang.Object.wait(Unknown Source)
         java.awt.EventQueue.invokeAndWait(Unknown Source)
         javax.swing.SwingUtilities.invokeAndWait(Unknown Source)
         in.co.netsol.telecom.desktop.command.EmergencyCommand$EventAdapter$1.run(EmergencyCommand.java:146)
         java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
         java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
         java.lang.Thread.run(Unknown Source)
    Thanks & Regards,
    Pradeep Gupta

    Update to the latest version 1.5.0_06 available from:
    http://java.sun.com/j2se/1.5.0/download.jsp
    It is advisable to remove previous version(s) installations unless required otherwise for a specfic application.

  • Problem in JOptionPane

    Hi,
    Here's my problem, I'm making a dialog box with a JOptionPane
    and I'm using a OK_CANCEL_OPTION and the method showOptionDialog(...).
    When I click on the Cancel button, the value returned is 1
    but the constant JOptionPane.CANCEL_OPTION=2.
    I have to put an else to put the value of cancelled to true.
    So what's the matter ?
    int choice = JOptionPane.showOptionDialog(null, ConnectionPanel, title,
                             JOptionPane.OK_CANCEL_OPTION,
                             JOptionPane.INFORMATION_MESSAGE, null,
                             ConnectOptionNames, ConnectOptionNames[0]);                                                  
    System.out.println("choice : " + choice);
    System.out.println("CANCEL_OPTION" + JOptionPane.CANCEL_OPTION);
    if (choice == JOptionPane.OK_OPTION) {       
        System.out.println("OK_OPTION" + JOptionPane.OK_OPTION);          
    } else if (choice == JOptionPane.CANCEL_OPTION) {     
        // why is this value never got ?
        // JOptionPane.CANCEL_OPTION=2 but choice=1
        cancelled = true;
        System.out.println("CANCEL_OPTION" + JOptionPane.CANCEL_OPTION);
    } else if (choice == JOptionPane.CLOSED_OPTION) {               
        cancelled = true;
        System.out.println("CLOSED_OPTION" + JOptionPane.CLOSED_OPTION);
    } else cancelled = true; // another bug of Java---------------------
    Thanks in advance
    Yann P.
    JOnAS 2.5 http://www.objectweb.org/jonas/
    ------------------

    that JOptionPane.CANCEL_OPTION is the int taken by the joptionpane constructor to tell it to display only a cancel option...
    track the int it returns and set it as that, as the int will never change!

  • 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.

  • 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

  • JDialog & JOptionPane Problems

    I want to display a message(propably JOptionPane) which doesn't have the default answers such as "YES", "NO" or "CANCEL". Bu i want to add my options. I try with JDialog but the owner is a JInternalFrame and not a JFrame as it must be.
    What i must do?
    Any help is appreciated?

    Object[] options = {"java", "C++", "C#"};
    int option =JOptionPane.showOptionDialog(null,"Which language do you like best?","PROGRAM CHOICE",
    JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null,options,options[0]);
    if(option==0) System.out.println("Youchose java");
    else if(option==1) System.out.println("Youchose C++");
    else System.out.println("Youchose C#");

Maybe you are looking for