Results 1 to 10 of 10
  1. #1
    ddonn is offline Member
    Join Date
    Nov 2011
    Posts
    18
    Rep Power
    0

    Default JOptionPane display on seperate lines

    Hi everyone,
    I am trying to display an output message using JOptionPane. I want to display the message on a number of lines. I have tried numerous ways and can't seem to find a solution. If anyone could give me a simple example or provide a link to where I could find a solution, it would be greatly appreciated.

    Here's an example of what i'm trying to do;

    import javax.swing.JOptionPane;
    public class NewLine
    {
    public static void main(String[] args)
    {
    JOptionPane.showMessgeDialog(null, "hello")/n
    ("my name is: ")/n
    ("xxxx");
    System.exit(0);
    }
    }

    Thanks in advance.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,023
    Blog Entries
    7
    Rep Power
    20

    Default Re: JOptionPane display on seperate lines

    According to the API documentation, if the message parameter is a Component it will be displayed as is; a JTextArea (for example) is such a Component.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    ddonn is offline Member
    Join Date
    Nov 2011
    Posts
    18
    Rep Power
    0

    Default Re: JOptionPane display on seperate lines

    I'm sorry, i'm very new to this. What does that mean?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,023
    Blog Entries
    7
    Rep Power
    20

    Default Re: JOptionPane display on seperate lines

    Quote Originally Posted by ddonn View Post
    I'm sorry, i'm very new to this. What does that mean?
    Have you read the API documentation?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    ddonn is offline Member
    Join Date
    Nov 2011
    Posts
    18
    Rep Power
    0

    Default Re: JOptionPane display on seperate lines

    I have now but i still don'y understand what you are saying

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,023
    Blog Entries
    7
    Rep Power
    20

    Default Re: JOptionPane display on seperate lines

    Ok, we'll do it the other way around: does that 'message' parameter have to be a String?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    ddonn is offline Member
    Join Date
    Nov 2011
    Posts
    18
    Rep Power
    0

    Default Re: JOptionPane display on seperate lines

    The example i provided in my first message was only a tiny piece of my program. The input from the JOptionPane input window is a String but is then converted to an int.

    Kind Regards,

    David

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,023
    Blog Entries
    7
    Rep Power
    20

    Default Re: JOptionPane display on seperate lines

    Quote Originally Posted by ddonn View Post
    The example i provided in my first message was only a tiny piece of my program. The input from the JOptionPane input window is a String but is then converted to an int.
    That's not what I asked; I'll rephrase my question: according to the API documentation that 'message' parameter can be an array of objects or a Component (or a simply String). Can you supply an array of Strings? Or a Component that displays multiple lines of text? Read the first part of that API documentation again and don't go hunting for a method that does it all for you.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    ddonn is offline Member
    Join Date
    Nov 2011
    Posts
    18
    Rep Power
    0

    Default Re: JOptionPane display on seperate lines

    I'm not going to get what i'm looking for here. I am a complete beginner. Thanks for you time.

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: JOptionPane display on seperate lines

    Just pass a String[] as the message parameter.

    Moving to AWT/Swing.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 4
    Last Post: 05-15-2011, 04:47 AM
  2. Replies: 21
    Last Post: 10-15-2010, 09:20 AM
  3. Replies: 1
    Last Post: 10-29-2008, 07:50 AM
  4. [SOLVED] Writing ArrayList to Text File on seperate Lines
    By shinjitsunohana in forum New To Java
    Replies: 9
    Last Post: 08-27-2008, 05:53 PM
  5. JOptionPane Display Difficulties
    By kewlgeye in forum New To Java
    Replies: 7
    Last Post: 05-09-2008, 08:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •