首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在Java中显示同一jLabel中的不同行

如何在Java中显示同一jLabel中的不同行
EN

Stack Overflow用户
提问于 2015-08-03 20:42:49
回答 2查看 64关注 0票数 0

嘿,伙计们,我正在开发一个应用程序来读取目录、子目录和文件,这样就可以完美地工作了。

代码语言:javascript
运行
复制
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package avd;

import java.io.File;



/**
 *
 * @author USER
 */
public class arborescence {
   private String initialpath = "";
    private Boolean recursivePath = false;
    public int filecount = 0;
    public int dircount = 0;

/**
 * Constructeur
 * @param path chemin du répertoire
 * @param subFolder analyse des sous dossiers
 */
    public arborescence(String path, Boolean subFolder) {
        super();
        this.initialpath = path;
        this.recursivePath = subFolder;
    }

    public void list() {
        this.listDirectory(this.initialpath);
    }

    private void listDirectory(String dir) {
        File file = new File(dir);
        File[] files = file.listFiles();
        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory() == true) {
                    System.out.println("Dossier: " + files[i].getAbsolutePath());
                    FirstWindow.lblRepertoire.setText(files[i].getAbsolutePath());
                    this.dircount++;
                } else {
                    System.out.println("  Fichier: " + files[i].getName());
                    FirstWindow.lblFile.setText(files[i].getAbsolutePath());
                   this.filecount++;
                }
                if (files[i].isDirectory() == true && this.recursivePath == true) {
                    this.listDirectory(files[i].getAbsolutePath());
                }
            }
        }
    }    
}

在主类中,我有以下内容:

代码语言:javascript
运行
复制
public void  scanfiles(){
 String pathToExplore = fileName;
 arborescence arbo = new arborescence(pathToExplore, true);
  Long start = System.currentTimeMillis();
  arbo.list();
  System.out.println("----------");
  System.out.println("Analyse de " + pathToExplore + " en " + (System.currentTimeMillis() - start) + " mses");
  lbltime.setText(Integer.toString((int) (System.currentTimeMillis() - start)));
  System.out.println(arbo.dircount + " dossiers");
  lblCountRep.setText(Integer.toString(arbo.dircount));
  System.out.println(arbo.filecount + " fichiers");
  lblCountFiles.setText(Integer.toString(arbo.filecount));
}

这是我的相框

问题是,在标签“曲目”,它告诉我,最后一个,我想,它显示给我每一个喜欢,当反病毒扫描你的文件时,你看到它正在扫描什么,我们可以这样做吗?

EN

Stack Overflow用户

发布于 2015-08-03 20:54:19

This就是一个这样做的例子。不确定你是否在寻找同样的东西。实际上html为你做了一些事情。

代码语言:javascript
运行
复制
JLabel label = new JLabel("<html>First line and maybe second line</html>");

通过使用适当的布局使您的jlabel可伸缩。可能是网格袋布局。它应该能做到这一点。

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31787600

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档