Align the text / message of a JOptionPane

0

I have several JOptionPane that show messages, example:

JOptionPane.showMessageDialog(loginFrame, "          Login Successful");

When I write the message as in the example, I have to put a space before Login Successful so that it looks aligned in the middle of the dialogue if I do not do it the message looks like this:

And I do not like it aesthetically.

Is there any way to align the text / message without having to do it manually with blank spaces?

EDIT:

Try this:

JOptionPane.showMessageDialog(loginFrame, new JLabel("Login Successful", JLabel.CENTER));

And it does not work, the result:

    
asked by Bryan Romero 06.12.2018 в 09:19
source

1 answer

1

JOptionPane has a JLabel inside, so we can create a new one, instanting it again, and giving it the attributes we want:

JOptionPane.showMessageDialog(loginFrame, new JLabel("Login Successful", JLabel.CENTER));
    
answered by 06.12.2018 / 09:27
source