1

このコードは実際に機能しますが、別の方法で記述できると思います。不確定な進行状況バーを表示するために使用しているカスタム JDialog があります。右、while ループ内でタイトル、可視性、および場所を設定します。これは機能しますが、ワーカーを作成した場所のすぐ下に表示する必要があると思いますが、そうすると不正なタイプの開始エラーが発生します。何か案は?ありがとう。

SwingWorker worker = new SwingWorker<Void, Void>(){
           //I am thinking this should work, but it doesn't
//              Progress.setTitle("Loading Repository");
//              Progress.setLocationRelativeTo(null);
//              Progress.setVisible(true); 
            @Override
            protected Void doInBackground() throws Exception {
                    while (runLoad.getState() != Thread.State.TERMINATED && !isCancelled()) {
                        try {
                            Progress.setTitle("Loading Repository");
                            Progress.setLocationRelativeTo(null);
                            Progress.setVisible(true);  
                            synchronized (this) {
                                Thread.sleep(2000);
                            }
                        } catch (InterruptedException e) {
                            JOptionPane.showMessageDialog(null,
                                    "Process interrupted: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                        }
                    }
                    return null;
                }
            @Override
            public void done() {
                SwingUtilities.invokeLater(new Runnable() {
                   @Override
                   public void run() {
                     Progress.setVisible(false);
                     Progress.dispose();
                    }
                 });
               }
            };
            worker.execute();
4

1 に答える 1