简体   繁体   English

在JOptionPane中对齐文本

[英]Justify text inside JOptionPane

I have the following line of code 我有以下代码行

JOptionPane.showMessageDialog(rootPane, "Código incorreto\nPor favor verifique", "Atenção", JOptionPane.ERROR_MESSAGE);

that show this message here 在这里显示此消息

在此处输入图片说明

How to center this 2 lines of text in the center of the box? 如何将这2行文本居中于框的中心?

JLabel label = new JLabel("<html><center>Código incorreto<br>Por favor verifique");
label.setHorizontalAlignment(SwingConstants.CENTER);
JOptionPane.showMessageDialog(null, label, "Atenção", JOptionPane.ERROR_MESSAGE);

Try this one. 试试这个。 Preview: 预习:

在此处输入图片说明

You may get it working with following code: 您可以通过以下代码使用它:

String message = "<html><body><div width='100px' align='center'>Código incorreto<br>Por favor verifique</div></body></html>";
JLabel messageLabel = new JLabel(message);
JOptionPane.showConfirmDialog(null, messageLabel, "Atenção", JOptionPane.DEFAULT_OPTION);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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