Here, ImageIcon imageIcon = new ImageIcon(ImageIO.read(flist[i])); it is taking too much time (12 to 15 sec) so I want to create JProgressBar when it is taking time, once JList is open thn Jprogress bar should be disable or dispose, please help me..
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
}
}