java - 我想在 For 循环运行时运行 JProgressBar,可以吗?
问题描述
这里, ImageIcon imageIcon = new ImageIcon(ImageIO.read(flist[i])); 它花费了太多时间(12到15秒)所以我想在需要时间的时候创建JProgressBar,一旦JList打开,Jprogress bar应该被禁用或处置,请帮助我..
public static void searchPath(JComboBox<String> comboBox_1) throws IOException {
DefaultListModel<Serializable> model = new DefaultListModel<Serializable>();
int count = 0;
String dDrivePath="\\StandardPath\\MyFolder\\"+comboBox_1.getSelectedItem() + "\\";
String filename = "..\\config\\config.txt";
BufferedReader reader = new BufferedReader(new FileReader(filename));
try {
String line; // as long as there are lines in the file, print them
while ((line = reader.readLine()) != null) {
File file = new File("\\"+"\\"+line+"\\d$" + dDrivePath);
System.out.println("Access Path : "+ " "+file);
File[] flist = file.listFiles();
@SuppressWarnings("unchecked")
JList<Serializable> sList = new JList<Serializable>(model);
sList.setBackground(UIManager.getColor("Button.background"));
for (int i = 0; i < flist.length; i++) {
// model.addElement(flist[i]);
String name = flist[i].toString();
if (name.endsWith("jpg")) {
ImageIcon imageIcon = new ImageIcon(ImageIO.read(flist[i]));
//Taking Too Much Time...
model.add(count++, scaleImage(imageIcon, 100, 120));
}
}
sList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
sList.setVisibleRowCount(-1);
sList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
sList.setFixedCellWidth(250);
sList.setFixedCellHeight(250);
JFrame frame = new JFrame(comboBox_1.getSelectedItem() +" "+ "Color");
frame.getContentPane().add(new JScrollPane(sList));
frame.getContentPane().setPreferredSize(new Dimension(1360, 768));
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
} catch (Exception e) {
// TODO: handle exception
}
}
解决方案
推荐阅读
- php - Nova Relatable Filtering - 如何过滤 company_id 与位置 company_id 匹配的用户
- java - 为什么 toMap 放置不当会导致 RXJava 出现问题?
- javascript - Highcharts:如何在多系列图表中使用数据集设置每列,每个系列的颜色?
- git - 暂存修改的文件
- sass - Gulp SaSS 任务中的 Font Awesome 未定义变量
- java - openjfx 1.8 不包含 javafx.fxml 包
- python - 我在 Python 上的 Selenium 项目中遇到问题
- spf - 如何结合这两个 SPF 记录?
- python - 通过 Python Flask 创建 SQLite 数据库时出现“未找到应用程序”错误
- java - Travis 使用 ant 代替 maven