Buen señores no se porque no captura el evento del teclado tengo mi codigo asi :
Código (java) [Seleccionar]
private JPanel createToolbar() {
final JPanel panel = new JPanel();
panel.setBackground(Color.GREEN);
panel.setLayout(new FlowLayout());
panel.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
System.out.println("Pressed " + e.getKeyChar());
}
@Override
public void keyReleased(KeyEvent e) {
System.out.println("Pressed " + e.getKeyChar());
}
@Override
public void keyPressed(KeyEvent e) {
// startCapture();
System.out.println("Pressed " + e.getKeyChar());
}
});
panel.setFocusable(true);
panel.requestFocusInWindow();
//KeyListener listener = new MyKeyListener();
//panel.addKeyListener(listener);
//panel.setFocusable(true);
// panel.KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this)
//KeyboardExampl keyboardExample = new KeyboardExample();
//panel.add(keyboardExample);
// capturing = false;
// btnStartStop = new Button("Compartir Recorte");
// btnStartStop.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// if (capturing) {
// capturing = false;
// btnStartStop.setLabel("Start Capture");
// stopCapture();
// } else {
// capturing = true;
// btnStartStop.setLabel("Stop Capture");
// System.out.println("Capturando ");
// startCapture();
// }
// }
// });
// Detener_frame = new Button("Detener Recorte");
// Detener_frame.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// startCapture();
// stopCapture();
// }
// });
//btnStartStop.setFocusable(true);
// panel.add(btnStartStop);
// panel.add(Detener_frame);
panel.setFocusable(true);
// panel.setVisible(false);
return panel;
}