JLabel和JTextField setText不是更新 [英] JLabel and JTextField setText is not update

查看:655
本文介绍了JLabel和JTextField setText不是更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用setText()方法更新jlabel和jtextfield,但它不起作用。但是,其余代码正在运行。代码如下;

I want to update jlabel and jtextfield with setText() method but it is not working. However, rest of the code is working. The code is below;

btnDosyaSe.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                JFileChooser jfc = new JFileChooser();
                jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

                int kullaniciSecimi = jfc.showOpenDialog(null);
                if (kullaniciSecimi == JFileChooser.APPROVE_OPTION) {
                    File fileName = jfc.getSelectedFile();
                    textField.setText(fileName.getPath());
                    islemSureci.setText("Veriler Okunuyor...");

                    try {

                        ArrayList<ArrayList<String>> tumYazılar = rwd.readTXT(fileName.getPath());
                        String[] yazarlar = rwd.yazarlar(fileName.getPath());
                        islemSureci.setText("Veriler Okundu! Öznitelik çıkarımına başlandı...");

                        oznitelikler = oc.oznitelikleriBul(tumYazılar, yazarlar);
                        islemSureci.setText("Öznitelikler Çıkarılmıştır!");
                        //String text = readTXT(fileName);

                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        });

在这里,islemSureci是JLabel,textFiled是JTextField。当它们被设置时,它不起作用。完成代码中的所有工作后,它们就会出现。请问你能说出原因是什么吗?

In here, islemSureci is JLabel and textFiled is JTextField. When they are set, it is not working. After all the work finish in the code, they appear. Please can you tell what is the reasons?

推荐答案

我认为你的意思是完成所有工作后正在从文件中加载文字(你评论的那一行)。我认为这段代码工作正常,因为你在设置文本后没有做任何事情。
你可以使用另一个线程加载文本,如果是真的。

I think you mean by "After all the work finish" is loading text from the file(the line you commented). I think this code works fine because you don't do nothing after setting the text. You can use another thread to load text, if it is true.

如果 oc.oznitelikleriBul()需要很长时间,您可以在不同的线程中编写该行和文本设置行。但是,在这种情况下,请确保在 EDT中运行文本设置行在新线程中。

If oc.oznitelikleriBul() takes a long time, you can code that line and text setting line in a different Thread. But, in that case make sure to run text setting line in an EDT inside the new Thread.

这篇关于JLabel和JTextField setText不是更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆