繁体   English   中英

Java Swing为输出创建文本区域

[英]Java Swing create a Text Area for the Output

您好我是Java编程的新手,我创建了一个带有一些选项和文件选择器的Java菜单。 因此,在我的IDE中,我打印出文件名和用户选择的文件的路径。 有什么方法可以在我的框架上创建文本区域,以便用户可以看到实际的输出? 这是我的文件选择器的样子以及如何在控制台上输出结果。

   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());

这是我的菜单的代码

    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);

我需要的是一个文本区域,所以我可以输出文件名和框架上的路径。

查看文档 ,这解释了JTextArea的使用。 它非常简单,您可以使用它做很多事情。 它肯定会对你有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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