Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6076349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:35:50+00:00 2026-05-23T10:35:50+00:00

How can you process command line arguments in a Java Swing program? EDIT: What

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:35:51+00:00Added an answer on May 23, 2026 at 10:35 am

    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 d

    For example to print them out as an array of command line arguments:

    public static void main(String[] args)
    {
        for(String arg : args)
            System.out.println(arg);
    }
    

    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:

    JTextPane pane = new JTextPane();
    JFrame frame = new JFrame("Example");
    frame.add(pane);
    frame.setVisible(true);
    File file = new File(args[0]);
    pane.setPage(file.toURL().toString());
    frame.pack();
    

    If you want more than one files contents just use java NameOfClassFile file1 file2 file3
    Then you can use args[0] args[1] args[2] to get the file path and modify the above code to put on a JTextPane.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to develop a command-line program that can process and give help
My program basically runs a executable file with command line arguments. A child process
How can I obtain the command line arguments of another process? Using static functions
Is there a command-line program that can process pngs(and other formats) to make them
I'm using Boost Program Options Library to parse the command line arguments. I have
I can run a command line process using process.start() . I can provide input
I have a command line process that needs to use code in one of
In Python, how can we find out the command line arguments that were provided
I'm writing a Perl program that will take a few command-line arguments (they'll actually
i want to convert an avi file to 3gp using java program. For this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.