X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FJvOptionPane.java;h=7a5daf705eb1ba3f8856d8874fa46ca6a5255669;hb=e57f77dc13f5a295cf49a403da05770a68a6e22b;hp=0a7c49ea2a1d758c7daa174d58499bc555cddc8d;hpb=1213d49ca3df8f48360da857121805d088c13aab;p=jalview.git diff --git a/src/jalview/gui/JvOptionPane.java b/src/jalview/gui/JvOptionPane.java index 0a7c49e..7a5daf7 100644 --- a/src/jalview/gui/JvOptionPane.java +++ b/src/jalview/gui/JvOptionPane.java @@ -859,8 +859,9 @@ public class JvOptionPane extends JOptionPane break NOTNULL; } - // run through buttons for initialValue first so can set a final - // timeoutThreadF + // 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++) { @@ -868,11 +869,10 @@ public class JvOptionPane extends JOptionPane JButton jb = buttons[i]; if (o.equals(initialValue)) { - initialValueButton = jb; - if (timeout > 0 && initialValueButton != null - && initialValueButton instanceof JButton) + if (timeout > 0 && jb != null && jb instanceof JButton) { - Runnable timeoutClose = () -> { + // after timeout ms click the default button + timeoutThread = new Thread(() -> { try { Thread.sleep(timeout); @@ -882,13 +882,17 @@ public class JvOptionPane extends JOptionPane "Dialog timeout interrupted. Probably a button pressed."); } jb.doClick(); - }; - timeoutThread = new Thread(timeoutClose); + }); } + initialValueButton = jb; + break; } } final Thread timeoutThreadF = timeoutThread; - timeoutThreadF.start(); + if (timeoutThreadF != null) + { + timeoutThreadF.start(); + } int[] buttonActions = { JOptionPane.YES_OPTION, JOptionPane.NO_OPTION, JOptionPane.CANCEL_OPTION }; @@ -1330,6 +1334,7 @@ public class JvOptionPane extends JOptionPane // A better hack which works is to create a new JFrame parent with // setAlwaysOnTop(true) + boolean parentOnTop = dialogParent.isAlwaysOnTop(); dialogParent.setAlwaysOnTop(true); parentComponent = dialogParent; @@ -1337,6 +1342,8 @@ public class JvOptionPane extends JOptionPane JOPTIONPANE_MESSAGETYPE, icon, options, initialValue, modal, buttons); + dialogParent.setAlwaysOnTop(parentOnTop); + if (dispose) { dialogParent.setAlwaysOnTop(false);