[英]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. 您好我是Java编程的新手,我创建了一个带有一些选项和文件选择器的Java菜单。 Therefore in my IDE I print out the file name and the path of the file that the user chooses.
因此,在我的IDE中,我打印出文件名和用户选择的文件的路径。 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. 我需要的是一个文本区域,所以我可以输出文件名和框架上的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.