JOptionPane does not execute here, why?
Code:
import javax.swing.JOptionPane;
import java.util.Scanner;
public class Strings {
/**
* @param args
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter a word...");
String s1 = input.next();
System.out.println("s1 is " + s1);
String message = "Java is fun";
JOptionPane.showMessageDialog(null, message);
}
}
Re: JOptionPane does not execute here, why?
Re: JOptionPane does not execute here, why?
Ok. I cmd the Strings class and it does work. The problem happens on Eclipse/helios. I run the app and after I enter the word on the console no dialog box.
Re: JOptionPane does not execute here, why?
What do you mean by "I cmd the String class"? Specifically, what does "cmd" mean? And also, I too get the dialog. Please give any more details of what's going on if possible.
Re: JOptionPane does not execute here, why?
By cmd I meant going to C://javaProject/bin/Strings.class and run the java Strings command. That works fine. The problem I am having is in Eclipse.
Re: JOptionPane does not execute here, why?
Quote:
Originally Posted by
nome
By cmd I meant going to C://javaProject/bin/Strings.class and run the java Strings command. That works fine. The problem I am having is in Eclipse.
Hm, it works fine for me in Eclipse Indigo release.
Re: JOptionPane does not execute here, why?
Tried on Indigo on a different machine and same problem.
Re: JOptionPane does not execute here, why?
I have test the same with Eclipse Helios and works fine. However the message box not popups on the IDE, it could be behind it. There is nothing related with IDE in your code. Check it again.
Re: JOptionPane does not execute here, why?
Quote:
Originally Posted by
Fubarable
Hm, it works fine for me in Eclipse Indigo release.
It works fine on Eclipse Helios as well, which is the version I am using right now.
Re: JOptionPane does not execute here, why?
Quote:
Originally Posted by
nome
Tried on Indigo on a different machine and same problem.
Since I can't replicate your problem, I can't understand it -- sorry.
But just for grins, what if you change input.next() to input.nextLine() so you fully handle the end of line token:
Code:
String s1 = input.nextLine();
And if that doesn't work, what if you specify the JOptionPane to show up on the Swing thread, the EDT:
Code:
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import java.util.Scanner;
public class Strings {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter a word...");
String s1 = input.nextLine();
System.out.println("s1 is " + s1);
final String message = "Java is fun";
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog(null, message);
}
});
}
}
Re: JOptionPane does not execute here, why?
Eranga et all..
Sorry, I feel like such a moron, the popup does work, it's just behind the window. It's curious thought that it does that. If I was to call the JOptionPane all by itself it pops up in front, regularly.
Thanks for your patience.
Re: JOptionPane does not execute here, why?
You are welcome.
If something going wrong where I have confidence on that couldn't be, I am always looking into the basis. That practice makes my life so easy.