posted 15 years ago
I have a JFrame that contains three panels: two panels for buttons and text boxes and one custom JPanel. The panels for the buttons and text boxes are north and south and the custom one is in the center. I need to get focus to my center panel for registering keystroke events, but the focus won't leave my other components, even if I click the center panel. I have MouseListeners set up for that panel which work, but even when I'm using them the text focus stays in the text boxes. The constructor for the frame is below. How do I get focus to the panel in the center? I've tried Key Bindings and those don't seem to work either because they still seem to need focus (as in the passed constant JComponent.WHEN_FOCUSED), or else I don't know how to make them where they don't need it. Even if you know a way, I would like to know how to get focus to my panel.
public TableClientFrame(ClientModel m) {
super(m);
// initial frame settings
frame = new JFrame("Client Frame");
frame.setSize(400, 400);
frame.setBackground(Color.WHITE);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// the model
this.model = m;
// add the panel
panel = new TableClientPanel(model);
frame.add(panel, BorderLayout.CENTER);
m.addListener(panel);
frame.add(controlPanel(), BorderLayout.SOUTH);
frame.add(connectPanel(), BorderLayout.NORTH);
}