+
+ // run through buttons for initialValue first so we can set (and start)
+ // a final timeoutThreadF to include (and interrupt) in the button
+ // actions
+ Thread timeoutThread = null;
+ for (int i = 0; i < options.length; i++)
+ {
+ Object o = options[i];
+ JButton jb = buttons[i];
+ if (o.equals(initialValue))
+ {
+ if (timeout > 0 && jb != null && jb instanceof JButton)
+ {
+ // after timeout ms click the default button
+ timeoutThread = new Thread(() -> {
+ try
+ {
+ Thread.sleep(timeout);
+ } catch (InterruptedException e)
+ {
+ Console.debug(
+ "Dialog timeout interrupted. Probably a button pressed.");
+ }
+ jb.doClick();
+ });
+ }
+ initialValueButton = jb;
+ break;
+ }
+ }
+ final Thread timeoutThreadF = timeoutThread;
+ if (timeoutThreadF != null)
+ {
+ timeoutThreadF.start();
+ }
+