Handling the Event Dispatch Thread

前端 未结 4 1381
一个人的身影
一个人的身影 2021-01-01 06:22

I have a question about the \'Event Dispatch Thread\'. I have a Main class that is also a JFrame. It initialises the rest of the components in the code, some of them do not

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-01 07:25

    Devon_C_Miller's answer is correct. I just want to point out a shortcut to invoking the event dispatch thread.

    Here's how I start all of my Swing applications.

    import javax.swing.SwingUtilities;
    
    import com.ggl.source.search.model.SourceSearchModel;
    import com.ggl.source.search.view.SourceSearchFrame;
    
    public class SourceSearch implements Runnable {
    
        @Override
        public void run() {
            new SourceSearchFrame(new SourceSearchModel());
    
        }
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new SourceSearch());
        }
    
    }
    

    You can copy this to every Swing project, just by changing the names.

提交回复
热议问题