Auf Thema antworten

Etwa so?

[code=Java]

import javax.swing.*;


public class Test {


    public void run() {

        JProgressBar bar = new JProgressBar();

        JButton button = new JButton("...");

        SwingWorker<Void,Void> worker = new SwingWorker<Void,Void>() {

            @Override

            public Void doInBackground() {

                try {

                    for (int i = 0; i < 100; i++) {

                        Thread.sleep(100);

                        setProgress(i);

                    }

                } catch (InterruptedException ex) {}

                return null;

            }

        };


        worker.addPropertyChangeListener(l ->

            bar.setValue(worker.getProgress()));


        button.addActionListener(e -> { worker.execute(); });

        JPanel p = new JPanel();

        p.add(bar);

        p.add(button);

        JOptionPane.showMessageDialog(null, p);

        System.exit(0);

    }


    public static void main(String[] args) {

        SwingUtilities.invokeLater(() -> new Test().run());

    }

}

[/code]



Oben