![]() Note that when you supply a null argument like that, the JOptionPane dialog will be centered on the user’s screen. JOptionPane.showMessageDialog(null, "A basic JOptionPane message dialog") If for some reason you don't have a reference to JFrame or JWindow instance, you can make that field null, and still display the identical JOptionPane dialog, as shown in this example: In that example my first argument to the JOptionPane showMessageDialog method is a frame object, which presumably is an instance of a JFrame. When this line of code is executed it will display the following message dialog: JOptionPane.showMessageDialog(frame, "A basic JOptionPane message dialog") Starting with a simple example, if you just want to show a JOptionPane dialog with a simple text message, all you need is one line of Java source code, like this: I’ll walk you through some JOptionPane examples here, starting with a simple example and then increasing the level of difficulty as I go on. I’ve been working with the Java JOptionPane showMessageDialog a lot lately, so I thought I’d create a page here with a number of showMessageDialog examples, sort of a JOptionPane reference page. A $2 donation will help keep this site running!
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |