0
Q
遍歷一組複選框
A
回答
1
下面是基於How to Use the Focus Subsystem教程,註冊爲向前右邊和後邊的箭頭和向後焦點遍歷鍵的例子。
import java.awt.AWTKeyStroke;
import java.awt.GridLayout;
import java.awt.KeyboardFocusManager;
import java.awt.event.KeyEvent;
import java.util.HashSet;
import java.util.Set;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
public class CheckBoxDemo {
private static void createAndShowGUI() {
JFrame frame = new JFrame("Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new GridLayout(2, 2, 10, 10));
frame.add(new JCheckBox("Bird"));
frame.add(new JCheckBox("Cat"));
frame.add(new JCheckBox("Dog"));
frame.add(new JCheckBox("Rabbit"));
Set<AWTKeyStroke> forwardKeys = frame.getFocusTraversalKeys(
KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
Set<AWTKeyStroke> newForwardKeys = new HashSet<AWTKeyStroke>(forwardKeys);
newForwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));
frame.setFocusTraversalKeys(
KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, newForwardKeys);
Set<AWTKeyStroke> backwardKeys = frame.getFocusTraversalKeys(
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
Set<AWTKeyStroke> newBackKeys = new HashSet<AWTKeyStroke>(backwardKeys);
newBackKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0));
frame.setFocusTraversalKeys(
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, newBackKeys);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
相關問題
- 1. 的jQuery遍歷複選框
- 2. 遍歷一個複選框列表
- 3. 循環遍歷複選框PHP
- 4. 遍歷行/複選框在radgrid控件
- 5. 如何遍歷所有選中的複選框?
- 6. 如何遍歷所有未選中的複選框?
- 7. 遍歷UL家長和取消選中複選框使用jQuery
- 8. .filter遍歷一個數組
- 9. 遍歷一個元組
- 10. Python:遍歷一組符號
- 11. 遍歷一個n元組
- 12. 遍歷一個BPEL數組
- 13. JavaScript數組一致遍歷
- 14. Psuedo隨機遍歷一組
- 15. Ocaml-遍歷一個元組
- 16. RoR遍歷一個組/ each_slice
- 17. 遍歷數組
- 18. 遍歷數組
- 19. 遍歷元組
- 20. 遍歷數組
- 21. 遍歷數組
- 22. 遍歷數組
- 23. 遍歷數組
- 24. 遍歷數組
- 25. 遍歷數組
- 26. 遍歷數組
- 27. 如何遍歷複合文字數組
- 28. 遍歷所有選中的複選框,並獲得輸入框的值在jquery
- 29. 如何使用JQuery遍歷枚舉的Check List(複選框)?
- 30. 如何遍歷表單上的所有複選框?