首页 > 解决方案 > 我想在 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
        }
    }
    

标签: java

解决方案


推荐阅读