I have several JOptionPanes that display messages, example:
JOptionPane.showMessageDialog(loginFrame, " Login Successful");
When I write the message like in the example, I have to put a space before Login Successful so that it looks aligned in the middle of the dialog if I don't the message looks like this:
And I don't like it aesthetically.
Is there a way to align the text/message without having to do it manually with whitespace?
EDIT:
Try this:
JOptionPane.showMessageDialog(loginFrame, new JLabel("Login Successful", JLabel.CENTER));
And it doesn't work, the result:
JOptionPane
has anJLabel
inside, so we can create a new one, instantiating it again, and giving it whatever attributes we want:I could propose a quick solution, friend, but it implies eliminating the icon that has a
JOptionPane.showMessageDialog(
parameter)
by default , which is the one that appears here:for this you have to remove the icon by inserting these parameters in the method:
JOptionPane.showMessageDialog(loginFrame, new JLabel("Login Successful", JLabel.CENTER), "Messaggio", JOptionPane.PLAIN_MESSAGE);
You would have something like this:
many years late, but there it is XD