Path: csiph.com!news.mixmin.net!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Andreas Leitgeb Newsgroups: comp.lang.java.programmer Subject: Default Button Doesn't Follow Focused Button Date: Wed, 26 Jul 2023 16:15:28 -0000 (UTC) Organization: A noiseless patient Spider Lines: 51 Message-ID: Reply-To: avl@logic.at Injection-Date: Wed, 26 Jul 2023 16:15:28 -0000 (UTC) Injection-Info: dont-email.me; posting-host="34b340a488b81bbb5fb042801439960f"; logging-data="1629691"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18AGkQY3SdHWT5uNnoI23J9" User-Agent: slrn/1.0.3 (Linux) Cancel-Lock: sha1:IsL+9bot2h97dZrtbfrW5FwYpzA= Xref: csiph.com comp.lang.java.programmer:39983 Imagine a simple Dialog (SSCCE at the bottom of this post) with just two buttons, one of which is initially set up as Default-button, such that a simple -key press would invoke it. In Windows, it seems to be "usual behaviour" that if I now use the Tab-key to set focus on any other button, then the focused button should temporally become the new "default"- button, until focus goes to something not-a-button, then the original default button would receive the blue frame again and become default again. As it seems, Java does not follow this principle: instead, one button is declared as default, and regardless of whether the focus is on a different button or not, -key would always invoke the initially set default button. Has anyone here ever needed to change his Java program to be less alien on Windows in that matter? Will I need to install Focus listeners on each component, and set the defaultButton to either the focused component (if it is a button), or the dialogs initial default (otherwise)? --- SSCCE --- Even when running it on Windows, the blue frame of the default button doesn't follow the focus when Tabbing. When Focus is moved to the Ok-button, the blue frame stays around the Cancel button. --- begin - Test.java --- import javax.swing.JOptionPane; public class Test { public static void main(String[] args) { JOptionPane.showOptionDialog(null, "My Message", "My Message Dialog", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new String[]{"Ok", "Cancel"}, "Cancel"); System.exit(0); } } --- end ---