JOptionPane multiline rendering ?

N

Nagesh

hi,

I am trying to add multilines to JOptionPane.showMessageDialog. But
JOptionPane is not rendering the lines as I want. It is ignoring the
new line character ("\n"). How can i add the multilines to JOptionPane.
If that is not possible can i fix the width of JOptionPane so that it
automatically comes in multilines.

I am trying the following code example.

JOptionPane.showMessageDialog(NULL,"First line \n.Second line.\n Third
line \n.etc....");

If any body knows pls let me know.

nagesh
 
R

Rhino

Nagesh said:
hi,

I am trying to add multilines to JOptionPane.showMessageDialog. But
JOptionPane is not rendering the lines as I want. It is ignoring the
new line character ("\n"). How can i add the multilines to JOptionPane.
If that is not possible can i fix the width of JOptionPane so that it
automatically comes in multilines.

I am trying the following code example.

JOptionPane.showMessageDialog(NULL,"First line \n.Second line.\n Third
line \n.etc....");

If any body knows pls let me know.

nagesh
I use the technique you show in your example and it works fine for me. Here
is one of my examples:

JOptionPane.showMessageDialog(null, "This dialog should contain
the 'checkeredFlag.gif'\nwhich has no embedded blanks in its name.", "Jar
Test",
JOptionPane.INFORMATION_MESSAGE, aboutIcon);

The message wraps right after the 'checkeredFlag.gif', just as you would
hope. I can't think of a reason why this technique should fail for you.

Rhino
 
A

Andrew Thompson

Nagesh said:
I am trying to add multilines to JOptionPane.showMessageDialog.

Rhino showed one way. Here is another.

JLabel message = new JLabel("<html><body>Swing components<br>" +
"render HTML");
JOptionPane.showMessageDialog(null, message);

HTH
 
N

Nagesh

I could not understand what u r trying to say regarding
'checkeredFlag.gif'. What i understand is it is just a mark for break
line in the output. I could not succeed in any one of the above
tricks. It is intersting how html engine has come into the picture(in
context of ANdrew Thopson) . I thought it has nothing to do with java.
Rendering i mean it("\n") should make the next line to come as a new
line.


thanks,
Nagesh
 
N

Nagesh

I am very Sorry,
It is working if i give directly String object as argument but it does
not work if i add the text to JTextButton and add the text button as
argument. The JTextButton i had used for the purpose of dragging the
message I am showing.

i.e.
JTextField textButton = new JTextField("First line\n. Second
line\n.etc..... " );
textButton.setDragEnabled(true);
JOptionPane.showMessageDialog(null,textbutton);


thanks,
Nagesh
 
N

Nagesh

Sorry,
It is working if i give directly String object as argument but it does
not work if i add the text to JTextButton and add the text button as
argument. The JTextButton i had used for the purpose of dragging the
message I am showing.

i.e.
JTextField textButton = new JTextField("First line\n. Second
line\n.etc..... " );
textButton.setDragEnabled(true);
JOptionPane.showMessageDialog(null,textbutton);


thanks,
Nagesh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top