Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

JOptionPane multiline rendering ?

Thread view: 
Nagesh - 03 Jan 2006 13:33 GMT
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
Rhino - 03 Jan 2006 14:11 GMT
> hi,
>
[quoted text clipped - 12 lines]
>
> 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
Nagesh - 04 Jan 2006 13:53 GMT
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
Nagesh - 04 Jan 2006 14:08 GMT
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
Nagesh - 04 Jan 2006 14:09 GMT
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
Andrew Thompson - 04 Jan 2006 03:22 GMT
>   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

Signature

Andrew Thompson
physci, javasaver, 1point1c, lensescapes - athompson.info/andrew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.