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.
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
Re: JOptionPane display on seperate lines
I'm sorry, i'm very new to this. What does that mean?
Re: JOptionPane display on seperate lines
Quote:
Originally Posted by
ddonn
I'm sorry, i'm very new to this. What does that mean?
Have you read the API documentation?
kind regards,
Jos
Re: JOptionPane display on seperate lines
I have now but i still don'y understand what you are saying
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
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
Re: JOptionPane display on seperate lines
Quote:
Originally Posted by
ddonn
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
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.
Re: JOptionPane display on seperate lines
Just pass a String[] as the message parameter.
Moving to AWT/Swing.
db