문제

I have a class extending AbstractTableModel and it pools Data from a Database, Since its a Swing Component I initialize it in EventQueue, the Problem is most of the operation such as getting Connection and Querying DB all runs in eventqueue hence it takes time to load the JTable. Is there a way to separate the two processes.

도움이 되었습니까?

해결책 2

If you need to do a time-consuming operation, to prevent the GUI from freezing you have to do it in a thread different than the Event Dispatcher Thread. Those threads are called Worker threads, an example on how to use them is detailed in this other question.

Edit: I have found a very nice introduction and example article here.

다른 팁

Use a SwingWorker for doing the heavy background tasks to avoid blocking the EDT.

You can set up the table in a thread separate from the event queue like this:

new Thread() {
    public void run() {
        // setup the table
    }
}.start();

This will result in the code in run being run in a new thread, which is what you want.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top