简体   繁体   English

如何在 showOptionDialog 中对齐/居中文本

[英]How to you justify/ center text in a showOptionDialog

Simple question related to centering text in a JOptionPane.showOptionDialog;与在 JOptionPane.showOptionDialog 中居中文本相关的简单问题;

I tried using the method for a regular JOptionPane using JLabels but that method did not work as the JOptionPane.showOptionDialog method overrides the input text.我尝试使用 JLabels 对常规 JOptionPane 使用该方法,但该方法不起作用,因为 JOptionPane.showOptionDialog 方法覆盖了输入文本。

JLabel warning = new JLabel()
int x = JOptionPane.showOptionDialog(warning,"I want this text \n to be centered","Confirm",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,finishedOptions, finishedOptions[0]);
warning.setHorizontalAlignment(SwingConstants.CENTER);

You can use HTML for the message body, for example:您可以将 HTML 用于邮件正文,例如:

String msg = "<html><center><b>I want this text</b></center><center>to be "
           + "<font color=blue>centered</font></center></html>";
JOptionPane.showMessageDialog(null, msg, "Confirm", JOptionPane.QUESTION_MESSAGE);

This message box above would look something like:上面的这个消息框看起来像:

在此处输入图片说明

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

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