Bonjour,
La touche flèche droite de mon clavier ne déclenche aucun évènement dans mon code :
Ni comme ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 public JFormattedTextField getTextFieldFQuantitePourcent() { if (textFieldFQuantitePourcent == null) { textFieldFQuantitePourcent = new JFormattedTextField(); textFieldFQuantitePourcent.setHorizontalAlignment(SwingConstants.RIGHT); textFieldFQuantitePourcent.setColumns(4); textFieldFQuantitePourcent.setText("%"); textFieldFQuantitePourcent.addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent arg0) { // On supprime tous les caractères non numérique if (! Character.isDigit(arg0.getKeyChar())) arg0.consume(); // On limite le nombre de chiffres à 3 if (textFieldFQuantitePourcent.getText().length() >= 3) arg0.consume(); } @Override public void keyReleased(KeyEvent arg0) { if (arg0.getKeyChar() == KeyEvent.VK_KP_RIGHT) { System.out.println("test"); } } }); } return textFieldFQuantitePourcent;
Pourquoi ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 if (arg0.getKeyChar() == KeyEvent.VK_RIGHT) { System.out.println("test"); }
Partager