0

Hello I am really new to Java programming and I have created a Java menu with some options as well as file chooser. Therefore in my IDE I print out the file name and the path of the file that the user chooses. Is there any way that I can create a text area on my frame so the user can see the actual output ? This is how my file chooser looks like and how I output the results on my console.

   JFileChooser chooser = new JFileChooser();
       File F = new File("C:/");
       File namedir;
       File namepath;    
       chooser.setCurrentDirectory(F);
       chooser.showOpenDialog(null);
       chooser.setDialogTitle("Choose file to play");
       chooser.setApproveButtonText("Play");
       namedir = chooser.getCurrentDirectory();
       namepath = chooser.getSelectedFile();
       System.out.print("the name of the the directory is "+namedir.getName());
       System.out.print("the name of the the path is "+namepath.getAbsolutePath());

And here is the code for my menu

    JFrame frame = new JFrame("Menu");
frame.setVisible(true);
frame.setSize(600,400);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//add the menu bar with the item browse
JMenuBar bar = new JMenuBar();
frame.setJMenuBar(bar);
JMenu search = new JMenu("Browse");
bar.add(search);

What I need is a text area so I can output the file name and the path on my frame.

1
  • Use JTextArea... setText according to what you want and simple add that area into your frame. Commented Apr 22, 2014 at 12:52

1 Answer 1

2

See docs, this explains the use of JTextArea. It is very simple and you can do alot of things using it. It will surely work for you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.