Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom title on JOptionPane message dialogs

When working with JOptionPane in Java, how do I make a custom title on a message dialog? I currently have:

JOptionPane.showMessageDialog(null, "You won the game in " + tries + " tries!");

I tried to add another parameter, and it gave me an error. Any ideas?

like image 900
Jerryg225 Avatar asked Jun 04 '26 08:06

Jerryg225


1 Answers

Try this

JOptionPane.showMessageDialog(null, "You won the game in 7 tries!", "my title", JOptionPane.INFORMATION_MESSAGE);

You need to supply the message type (4th param) so swing know which default icon to display.

like image 75
user931366 Avatar answered Jun 06 '26 23:06

user931366



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!