Use a Thread or a SwingWorker - any long running tasks placed on the EDT will clog up the UI.
Worker Threads and SwingWorker (The Java™ Tutorials > Creating a GUI With JFC/Swing > Concurrency in...