简体   繁体   中英

How to you justify/ center text in a showOptionDialog

Simple question related to centering text in a 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.

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:

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:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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