Java Swing UI Thread Event runModalProcess(String title, final Runnable runnable)

Here you can find the source of runModalProcess(String title, final Runnable runnable)

Description

run Modal Process

License

Open Source License

Declaration

public static void runModalProcess(String title, final Runnable runnable) 

Method Source Code


//package com.java2s;
/*//  ww w.  j  a  v  a2 s.  co m
 * Copyright (C) 2012 Brendan Robert (BLuRry) brendan.robert@gmail.com.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 */

import java.awt.BorderLayout;

import javax.swing.BorderFactory;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

public class Main {
    public static void runModalProcess(String title, final Runnable runnable) {
        //        final JDialog frame = new JDialog(Emulator.getFrame());
        final JProgressBar progressBar = new JProgressBar();
        progressBar.setIndeterminate(true);
        final JPanel contentPane = new JPanel();
        contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
        contentPane.setLayout(new BorderLayout());
        contentPane.add(new JLabel(title), BorderLayout.NORTH);
        contentPane.add(progressBar, BorderLayout.CENTER);
        //        frame.setContentPane(contentPane);
        //        frame.pack();
        //        frame.setLocationRelativeTo(null);
        //        frame.setVisible(true);
        //
        //        new Thread(() -> {
        //            runnable.run();
        //            frame.setVisible(false);
        //            frame.dispose();
        //        }).start();
    }
}

Related

  1. runInEventDispatchThreadAndWait(final Runnable r)
  2. runInSwingThread(final Runnable runnable)
  3. runInSwingThread(Runnable runnable)
  4. runLater(Runnable runnable)
  5. runLaterAndWait(final Runnable runnable)
  6. runNowInEdt(Runnable runnable)
  7. runOnDispatchThread(Runnable runnable)
  8. runOnEDT(final Runnable r)
  9. runOnSwingThread(Runnable doRun)