Here is a snippet
kit.insertHTML(doc, doc.getLength(), \"Hello\", 0, 0, null); try{ Thread.sleep(1000); }catch(Exception e){}
I am using
You are calling sleep on the EDT (Event Dispatching Thread). You should avoid this situation as indeed, it freezes the UI.
sleep
To avoid this situation, use a SwingWorker instead or as suggested by HFOE, use a Swing Timer