Menu

Home

Miguel Alejan. Moreno Barrientos

Toast is a Swing component which extends JWindow, so you can set any toast before showing using JWindow methods,
for instance;

mToast.setAlwaysOnTop(false);  // default true

Also, you can set the backend JLabel used by Toast by calling #getToastLabel(), although not all methods in JLabel produce a good result.

Example launchers:

public class Test 
{
    public static void main(String[] args) 
    {
        // show toast
        Toast t = new Toast( "Testing, 1,2,3...", Toast.TWO_SECONDS ).showToast();

        try { Thread.sleep( 4000 ); } 
        catch ( InterruptedException ignored ) {}

        // show again
        t.getToastLabel().setFont( new Font(Font.MONOSPACED, Font.PLAIN, 30) );
        t.getToastLabel().setBackground( Color.WHITE );
        t.getToastLabel().setForeground( Color.BLACK );     
        t.showToast();
    }
}
public class Launcher 
{
    public static void main(String[] args) 
    {
        final Toast[] toasts = {
            new Toast( "toast1", Toast.HALF_SECOND ),
            new Toast( "toast2", new Point( 100, 100 ), Toast.FOUR_SECONDS ),
            new Toast( "toast3", new Point( 500, 500 ), Toast.TWO_SECONDS ),
            new Toast( "toast4", new Point( 900, 0 ), Toast.ONE_SECOND ),
            new Toast( "toast5", new Point( 400, 300 ), 0 ),
        };

        Arrays.stream( toasts )
              .forEach( toast -> toast.getToastLabel().setBackground( new Color( 
                  new Random().nextInt( 0x1000000 ) ) ) );

        Arrays.stream( toasts )
              .forEach( Toast::showToast );
    }
}

Project Members:


MongoDB Logo MongoDB