Search code examples
javaswingappletmessagejoptionpane

How to change the title of java applet's message box?


Hey so i press on button and comes a message box, named "Message". How do i rename this title?

Searching for this but didn't find nowhere.

That's how i create a button and then activate it so message pops. Didn't paste whole code cause it's long, but that's pretty much it for this button.

private JButton readmeButton;

readmeButton = new JButton("Readme");
layout.setConstraints(readmeButton, constraints);
chartPanel.add(readmeButton);
readmeButton.addActionListener(this);

JOptionPane.showMessageDialog(null, "lalala");

Solution

  • JOptionPane.showMessageDialog has multiple overloads. One of them is showMessageDialog(Component parentComponent, Object message, String title, int messageType).

    You can use this:

    JOptionPane.showMessageDialog(null, "lalala", "title", JOptionPane.PLAIN_MESSAGE);
    

    other options for the last argument are ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE.