简体   繁体   中英

Java Swing create a Text Area for the Output

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM