为什么无法在JLabel上设置完整的文件路径?

时间:2014-03-16 09:14:20

标签: java swing jlabel filepath

我正在构建一个扫描目录的程序。我希望扫描的当前目录显示在JLabel上。我无法理解为什么不显示完整的文件目录。防爆。 - 显示“C:\ Program Files(86)”而不是“C:\ Program Files(x86)\ Java \ bin \ javaw.exe”。但是使用System.out.println(),将显示完整的目录。请帮帮我吗?感谢....

请参阅下面的代码:

[EDITED]

    public void search(){
    ....
        for (File file : listOfFiles) {
        String path = file.getPath().replace('\\', '/');

        changeLabelText(path); //set JLabel text
        System.out.println(path); //shows complete filepath
    ....
    }

    public void changeLabelText(String path){
        this.lblPath.setText(path);
    }

    //start scan 
    public void actionPerformed(ActionEvent e) {

    if (e.getSource() == btnStart) {
        new Thread(new Runnable() {
            public void run() {

                search();
            }
        }).start();
        }
     }

     //constructor
     public AuditFiles() {
     ...    
         btnStart = new JButton("Scan");
         btnStart.addActionListener(this);

         lblPath = new JLabel("Current Directory: ");
         lblPath.setPreferredSize(new Dimension(300, 20));
     ...
     }

0 个答案:

没有答案
相关问题