The choice window makes its list focused then it gains focus itself. So you can just press up/down and ENTER or ESC to choose without touching mouse

This commit is contained in:
Maxmtg
2011-09-04 15:43:00 +00:00
parent 936fae779e
commit 5382bb7587

View File

@@ -13,6 +13,8 @@ import javax.swing.event.ListSelectionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.util.AbstractList;
import java.util.List;
@@ -243,6 +245,10 @@ public class ListChooser<T> {
d = p.createDialog(p.getParent(), title);
if (minChoices != 0) d.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
jList.setSelectedIndex(0);
d.addWindowFocusListener(new WindowFocusListener() {
@Override public void windowGainedFocus(final WindowEvent e) { jList.grabFocus(); }
@Override public void windowLostFocus(final WindowEvent e) { }
});
d.setVisible(true);
d.dispose();
value = (Integer) p.getValue();