You could use javax.swing.Timer like this:
new Timer(10_000, (e) -> { frame.setVisible(false); frame.dispose(); }).start();
The advantage of using the javax.swing.Timer option is that it doesn't violate Swing threading rules.
As the Javadocs say:
The javax.swing.Timer has two features that can make it a little
easier to use with GUIs. First, its event handling metaphor is
familiar to GUI programmers and can make dealing with the
event-dispatching thread a bit simpler. Second, its automatic thread
sharing means that you don't have to take special steps to avoid
spawning too many threads. Instead, your timer uses the same thread
used to make cursors blink, tool tips appear, and so on.