How can you process command line arguments in a Java Swing program?
EDIT: What I want to do is have the user give a file path as the arg. Then I set the text of a jTextPane to the contents of that file.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The only way is through the main method when you run the Java class file.
You do the following in the command line once compiled;
java NameOfClassFile a b c dFor example to print them out as an array of command line arguments:
I don’t know of anyway to pass command line arguments to a currently running Java Swing program. Not sure if you can.
To display a files contents on a JTextPane you can use
args[0]a a command line argument to the file path using:If you want more than one files contents just use
java NameOfClassFile file1 file2 file3Then you can use
args[0] args[1] args[2]to get the file path and modify the above code to put on a JTextPane.