在控制台中显示多个详细信息,但不在文本区域中显示。如何在文本区域中显示特定行

沙芬·迪普罗

类搜索扩展了JFrame {

private Container container;
private Font font,font2;
private JLabel label;
private JTextField textField;
private JButton search;
private JTextArea textarea;

search(){
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setBounds(100,40,600,380);
    this.setTitle("SEARCH");

    container = this.getContentPane();
    container.setLayout(null);

    font = new Font("Courier New",Font.BOLD,14);
    font2 = new Font("Courier New",Font.BOLD,18);

    label = new JLabel("SEARCH : ");
    label.setBounds(40,20,150,50);
    label.setFont(font);
    container.add(label);

    textField = new JTextField();
    textField.setBounds(140,25,200,40);
    textField.setFont(font2);
    container.add(textField);

    search = new JButton("SEARCH");
    search.setBounds(370,25,110,37);
    search.setFont(font);
    container.add(search);

    textarea = new JTextArea();
    textarea.setBounds(40,85,500,200);
    textarea.setFont(font2);
    container.add(textarea);

    search.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String x = textField.getText();
            try{
                File file = new File("allinfo.txt");
                BufferedReader reader = new BufferedReader(new FileReader(file));
                String s = reader.readLine();
                while(s!=null){
                    String string[] = s.split(" ");
                    String a = string[0];
                    String b = string[1];
                    String c = string[2];
                    String d = string[3];

                    String f = a+" "+b+" "+c+" "+d;

                    if (x.equals(a)){
                        System.out.println(f);
                        textarea.setText(f);
                    }
                    s = reader.readLine();
                }
            }catch (FileNotFoundException e){
                e.printStackTrace();
            }catch (IOException e){
                e.printStackTrace();
            }
        }
    });


}

    public static void main(String[] args) {

    search frame = new search();
    frame.setVisible(true);

    }

}

这是一个搜索选项,我可以在其中搜索一个人的名字。如果有两个人的名字相同,则两个选项都应显示在文本区域中,但文本区域仅显示一个人的详细信息。但是控制台正在打印所有个人详细信息。我需要有关如何在textarea中显示所有详细信息的帮助。

雪人XL

代替

textarea.setText(f);

textarea.append(f + "\n");

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

反向显示文本区域中的行

如何在文本区域中显示所选选项的文本

在文本区域中显示选定的选项

如何从表单中获取值并显示在文本区域中?

如何拖动图像并在文本区域中显示图像

如何摆脱文本区域中显示的逗号?

在文本区域中显示所选文本

如何在Java应用程序的文本区域中显示html格式的文本?

来自 MySQL 数据库的数据通过 php 显示在文本字段中,但不在文本区域中

如何在文本区域中显示数据库中的多行

让所选的单选按钮显示在文本区域中

无法在文本区域中显示 HTML 上下文

如何在Java swing中一一读取多个文件并显示在同一文本区域中?

如何在文本区域显示特定文本?

JavaFX:如何滚动到文本区域中的特定行

我需要在文本区域中显示的列表的多个索引

在两个文本区域中按下回车键时如何显示 div?

如何使用PHP和MySQL在文本区域中显示两个最新帖子?

如何从下拉菜单中选择多个值,并在单击提交按钮时将其显示在文本区域中?

在文本区域显示文本

计算文本区域中的特定字符

通过部分显示文本区域中的数据来动态显示大量文本

在自定义文本区域中显示尖号而不显示其文本

在文本区域中选择行

是否可以从文本区域接收输入,然后在同一文本区域中显示输出?

使写在文本区域中的文本显示在另一页上

使用 PHP 从 MySQL 中读取文本(非 VARCHAR)字段未显示在 HTML 文本区域中

如何在文本区域中更改字体颜色

如何显示文本区域以供查看?