user3805970
user3805970

Reputation: 31

JOptionPane.showMessageDialog like System.out.printf

How can I do that JOptionPane.showMessageDialog be like System.out.printf?

I tried something like that:

JOptionPane.showMessageDialog(null, "Your name is %s", name);

But I get error.

Upvotes: 1

Views: 4272

Answers (1)

Davie Brown
Davie Brown

Reputation: 717

see the docs for what you can supply to this method: http://docs.oracle.com/javase/7/docs/api/javax/swing/JOptionPane.html

But what you could do in your case is:

to use '+' to concatenate the strings:

JOptionPane.showMessageDialog(null, "Your name is" + name);

or using String.Format:

JOptionPane.showMessageDialog(null, String.format("Your name is %s",name));

Assuming that name is a String and has a value defined.

Upvotes: 2

Related Questions