简体   繁体   中英

Changing the title of a JOptionPane?

What my program should do, is when you put in a string like "two", instead of a number, a popup will show up saying: You must enter positive numeric data! I have that part down, but I want to change the title on the top of the popup. Right now it just says "Message".

catch (NumberFormatException e)
{
   JOptionPane.showMessageDialog(this, "You must enter positive numeric data!");
}

I need it to look more like this: http://homepages.uc.edu/~thomam/OOProg_1/assignment3.html

By the way, I'm using NetBeans as my IDE.

Look at the JOptionPane API and you'll see showMessageDialog method overloads that take more parameters that will do what you need.

eg,

public static void showMessageDialog(Component parentComponent,
                 Object message,
                 String title,
                 int messageType)

If you're going to get one important fact/lesson from this answer, it will be contained in the first 5 words: "Look at the xxx API". Getting very familiar with the Java API will help you immensely in your Java studies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM