Java Swing UI Thread Event invokeOnEventDispatchThreadIfRequired(final Runnable runnable)

Here you can find the source of invokeOnEventDispatchThreadIfRequired(final Runnable runnable)

Description

invoke On Event Dispatch Thread If Required

License

Open Source License

Declaration

static void invokeOnEventDispatchThreadIfRequired(final Runnable runnable) 

Method Source Code

//package com.java2s;
/* Copyright (C) 2019  Matteo Hausner
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version./*from w  ww . j av a2s  .  c  om*/
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

import javax.swing.SwingUtilities;

public class Main {
    static void invokeOnEventDispatchThreadIfRequired(final Runnable runnable) {
        if (SwingUtilities.isEventDispatchThread())
            runnable.run();
        else
            SwingUtilities.invokeLater(runnable);
    }
}

Related

  1. invokeNow(Runnable runnable)
  2. invokeNowOrLater(Runnable run)
  3. invokeOnEDT(final Object target, final String methodName, final Object... args)
  4. invokeOnEDT(final Runnable aRunnable)
  5. invokeOnEventDispatchThread(Runnable r)
  6. invokeOnEventThread(Runnable r)
  7. invokeOnEventThread(Runnable r)
  8. invokeOnEventThread(Runnable runnable)
  9. isEDT()