Java Swing UI Thread Event checkForEventDispatchThread()

Here you can find the source of checkForEventDispatchThread()

Description

Checks whether the current thread is Swing EDT.

License

Apache License

Exception

Parameter Description
IllegalStateException when the current thread is not Swing EDT

Declaration

public static void checkForEventDispatchThread() throws IllegalStateException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import com.google.common.base.Preconditions;
import javax.swing.*;

public class Main {
    /**/* ww  w .  ja  v a2  s. c  o m*/
     * Checks whether the current thread is Swing EDT. If not - throws an Exception with an advice
     *
     * @throws IllegalStateException when the current thread is not Swing EDT
     */
    public static void checkForEventDispatchThread() throws IllegalStateException {
        Preconditions.checkState(SwingUtilities.isEventDispatchThread(),
                "The method that caused this trace must be called in the Event Dispatch Thread, see http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html");
    }
}

Related

  1. assertEventDispatcherThread()
  2. assertIsEDT()
  3. assertNotEventDispatchThread()
  4. callOnGUIThread(Runnable runnable)
  5. dispatchOnAWTThreadLater(Runnable r)
  6. dispatchOnAWTThreadNow(Runnable r)
  7. dispatchToEDT(Runnable runnable)
  8. doInBackground(final Runnable r)