Aligning Text in Center of JOptionPane

Hi,

I am trying to display messages using JOptionPane and a JDialog.

JOptionPane pane =new JOptionPane(message,

message_type,

option_type,

icon,

options,

initial_value){

publicint getMaxCharactersPerLineCount(){returndefault_characters_per_line;}

};

JDialog dialog = pane.createDialog(parent_component, title);

dialog.setVisible(true);

I want to be able to control the number of characters per line which I have found how to do, and to control the alignment of the text. I have not being able to work out how to control the alignment of the text. I would like to be able have the text centered so a long line followed by a short line is displayed nicely.

I have tried using <html><center>My Text</center></html>, however, 1stly the html tags are counted as character therefore shortening the 1st line and secondly is the message is over several line then the tag are broken up and not interpreted properly.

Any assistance greatly appreciated.

Leon

[1343 byte] By [lnem2a] at [2007-11-27 6:48:25]
# 1

[nobr]//Create the dialog.

final JDialog dialog = new JDialog(frame,

"A Non-Modal Dialog");

//Add contents to it. It must have a close button,

//since some L&Fs (notably Java/Metal) don't provide one

//in the window decorations for dialogs.

JLabel label = new JLabel("<html><p align=center>"

+ "This is a non-modal dialog.<br>"

+ "You can have one or more of these up<br>"

+ "and still use the main window.");

label.setHorizontalAlignment(JLabel.CENTER);

Font font = label.getFont();

label.setFont(label.getFont().deriveFont(font.PLAIN,

14.0f));

extract from

http://java.sun.com/docs/books/tutorial/uiswing/examples/components/DialogDemoProject/src/components/CustomDialog.java[/nobr]

suparenoa at 2007-7-12 18:21:48 > top of Java-index,Desktop,Core GUI APIs...