Problem with KeyListener
I'm going to develop an application with a TabbedPane including some tabs; in each tab I'd like to handle different shortcuts.
Each tab contains some components (Button, TextArea, ecc) which may be focused.
I added a KeyListener on each tab but when a component is focused it retains the event and so the panel' KeyListener can't catch it..
Here is a little example without KeyListener:
import javax.swing.*;
publicclass Sampleextends JFrame
{
public Sample()
{
super.setSize(500,400);
super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel1 =new JPanel();
panel1.add(new Button("Sample Component");
JPanel panel2 =new JPanel();
panel2.add(new Button("Sample Component");
JTabbedPane pane =new JTabbedPane();
pane.addTab("Tab 1", panel1);
pane.addTab("Tab 2", panel2);
super.add(pane);
}
privatevoid F1Pressed()
{
JOptionPane.showMessageDialog(this,"F1 Pressed");
}
privatevoid F2Pressed()
{
JOptionPane.showMessageDialog(this,"F2 Pressed");
}
publicstaticvoid main(String[] args)
{
new Sample().setVisible(true);
}
}
What should I add to succed in making panel handle shortcuts?
Thank you in advance.

