Q:

Delay function call without pausing application in Java

I want my application to show something in a label for a couple seconds and then change. But I don't want my application to be sleeping during this time. It must be functional.
wait() and sleep() will make my application not work during this time. Is there anything like javascript's setTimeout() in Java, that will continue executing the code and execute a line after a period of time?

A:

If you don't want to include more sophisticated libraries you might use javax.swing.Timer (as mentioned by @VGR), java.util.concurrent.ScheduledExecutorService or java.util.Timer.
Example using javax.swing.Timer:
JLabel label = new JLabel("Hello");

Timer timer = new Timer(15000, e -> label.setText("Bye"));

timer.setRepeats(false);
timer.start();

Example using ScheduledExecutorService (remember that the actual logic touching UI components probably must be run from the GUI thread (AWT event dispatch thread in case of Swing), not executor's thread):
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
JLabel label = new JLabel("Hello");

Runnable task = () -> SwingUtilities.invokeLater(() -> label.setText("Bye"));

executor.schedule(task, 15, TimeUnit.SECONDS);

The executor runs background threads so you should shutdown it when you no longer need it.

