【发布时间】:2014-06-06 20:34:01
【问题描述】:
您好,我是 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... 根据您的需要设置文本,然后将该区域简单地添加到您的框架中。
标签: java swing textarea output