<Swing Dev> A proposal for a behavior change about mnemonic key
Sean Chou
zhouyx at linux.vnet.ibm.com
Fri Apr 1 02:29:58 UTC 2011
Hi all,
In daily use, we may encounter a problem of mnemonic key: there may be
several
controls want the same key to be set as mnemonic key. It is not common but
it does exist.
Current openjdk implementation allows users to set a same mnemonic key
for
different controls; but during the execution, when the mnemonic key is
pressed,
the last control always gets the action. Users are not able to touch other
controls with
that mnemonic key. This may confuse them.
If all the controls with the same mnemonic key can be accessed through,
for
example, when the mnemonic key is pressed, the focus is moved to the last
control,
and when the mnemonic key is pressed again, the focus is moved to the second
control
with that mnemonic, it will give user the choice to select other controls.
Here is an example for the case:
package test;
import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
public class TestFocus extends JFrame {
public TestFocus() {
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
JRadioButton btn1,btn2,btn3;
btn1 = new JRadioButton("Yes");
btn1.setMnemonic('Y');
btn2 = new JRadioButton("Yup");
btn2.setMnemonic('Y');
btn3 = new JRadioButton("No");
btn3.setMnemonic('N');
btn3.setSelected(true);
ButtonGroup group = new ButtonGroup();
group.add(btn1);
group.add(btn2);
group.add(btn3);
pane.add(btn1,BorderLayout.NORTH);
pane.add(btn2,BorderLayout.CENTER);
pane.add(btn3,BorderLayout.SOUTH);
setSize(200,200);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestFocus();
}
}
--
Best Regards,
Sean Chou
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/swing-dev/attachments/20110401/05336562/attachment.html>
More information about the swing-dev
mailing list