Here you can find the source of flashMessage(final Window parent, String string, Color background, Color foreground, final long howLong)
public static void flashMessage(final Window parent, String string, Color background, Color foreground, final long howLong)
//package com.java2s; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dialog.ModalExclusionType; import java.awt.Point; import java.awt.Window; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.SwingUtilities; import javax.swing.border.BevelBorder; public class Main { public static void flashMessage(final Window parent, String string) { flashMessage(parent, string, Color.WHITE, Color.BLACK, 1000); }/*from w w w.j a v a2 s .c om*/ public static void flashMessage(final Window parent, String string, Color background, Color foreground, final long howLong) { final int fontSize = 20; final JLabel label = new JLabel(string); final JDialog dialog = new JDialog(parent); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setModalExclusionType(ModalExclusionType.NO_EXCLUDE); label.setFont(label.getFont().deriveFont(fontSize)); label.setBackground(background); label.setForeground(foreground); label.setBorder(new BevelBorder(BevelBorder.RAISED)); dialog.getRootPane().setLayout(new BorderLayout()); dialog.getRootPane().add(label); final Point point = parent.getLocation(); dialog.setLocation(point.x + parent.getHeight() / 2, point.y + parent.getWidth() / 2); dialog.setSize(fontSize * string.length() * 6 / 10, fontSize); dialog.setUndecorated(true); dialog.setVisible(true); dialog.setAlwaysOnTop(true); parent.requestFocus(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { Thread.sleep(howLong); } catch (InterruptedException e) { } dialog.dispose(); } }); } }