在actionPerformed中打开一个JProgressbar

时间:2015-08-28 13:48:49

标签: java swing jframe jprogressbar

我正在尝试在actionPerfomed中执行ProgressBar(我有一个带有按钮的界面来浏览文件夹和运行按钮)。目标是在按下运行按钮后启动进度条,但是当窗口出现时它全部为空白。

我有这个代码用浏览和运行按钮启动窗口:

final JFrame frame_project = new JFrame("PROJECT 22");
    final JPanel panel = new JPanel();
    frame_project.setSize(400,250);
    frame_project.add(panel);
    panel.setLayout(null);

    JButton button2 = new JButton("Browse");
    button2.setBounds(30, 30, 90, 25);
    panel.add(button2);

    final JButton buttonStartCompare = new JButton();
    buttonStartCompare.setText("RUN");
    buttonStartCompare.setBounds(100, 80, w/2, h/2);
    panel.add(buttonStartCompare);
    frame_project.setVisible(true);

然后,在行动中,我有这个:

    buttonStartCompare.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            JProgressBar it = new JProgressBar();
             frame_project.setVisible(false);
             JFrame frame = new JFrame("Progress Bar");
             JPanel panel = new JPanel();
             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             panel.add(it);
             frame.setContentPane(it);
             frame.pack();
             frame.setSize(250,100);
             frame.add(panel);
             frame.setVisible(true);
}
}

编辑:

这是Oracle中看到的完整代码。第一个" ProgressMonitorDemo.createAndShowGUI();"好的,第二个不行:

final JButton Button_Run = new JButton();
    Button_Run.setText("RUN");
    Button_Run.setBounds(140, 80, 100, 100);
    panel.add(Button_Run);

    ProgressMonitorDemo.createAndShowGUI();

    Button_Run.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {

            Button_Run.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

            if(fieldSheetsDirectory.getText().isEmpty()){
                JFrame frame_missing = PanelUtils.getErrorPanel("Please select the files ");
                Button_Run.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                frame_missing.setVisible(true);
                return;
            }

            final String path = fieldSheetsDirectory.getText();

            fieldPathRapport.setText("\\Rapport.xlsx");
            fieldPathOriginal.setText("\\Original.xlsx");
            fieldPathCartoo.setText("\\MyCarto draft V2.xlsx");

            long lStartTime_open = System.currentTimeMillis();

            String path_Raportt = path.concat(fieldPathRapport.getText());
            String path_Original = path.concat(fieldPathOriginal.getText());
            String path_MyCartoo = path.concat(fieldPathCartoo.getText());

            System.out.println(path);
            System.out.println("");

            XSSFWorkbook OriginalBook = FileUtils.OpenFile(path_Original);
            XSSFWorkbook RapportBook = FileUtils.OpenFile(path_Raportt);
            XSSFWorkbook MyCartoBook = FileUtils.OpenFile(path_MyCartoo);

            if(OriginalBook == null || RapportBook == null || MyCartoBook == null){
                return;
            } else {
                frame.setVisible(false);
            }



            //JFrame frame_sucess = PanelUtils.getFinalErrorPanel("Running...");
            //frame_sucess.setVisible(true);
            ProgressMonitorDemo.createAndShowGUI();

0 个答案:

没有答案