Refresh Page by pressing keys

I have a jframe with tabbed pane which tabedpane contain two jpanels.this jpanel contains some swing components.I want to refersh the the jframe when focus is on one of the panel component.My problem is i want to fresh the panel and jframe when i pressed function key say f2.This can be done by adding the keylistener to the main window it works only main window is focus. without adding key listeners to each component in the panels how can i refresh the whole jframe even when focused to some components in the jpanel.(i want to refresh the jrame when i press the key(f2) i want to refresh frame but by adding key listeners to frame or panel level but without adding each and every component

)

Any help highly appreciated...

Thank in advance

[769 byte] By [susthiyaa] at [2007-11-27 8:52:26]
# 1
Use a JMenu. Add a "Refresh" JMenuItem and assign an accelerator to the menu item.
camickra at 2007-7-12 21:07:55 > top of Java-index,Desktop,Core GUI APIs...
# 2

Another option is to establish a key binding to the Action you've defined from the root component's InputMap and ActionMap.

public static void establishKeyBinding(JComponent c, AbstractAction a) {

Object o = a.getValue(Action.ACCELERATOR_KEY);

if (o != null && o instanceof KeyStroke) {

establishKeyBinding(c, a, (KeyStroke) o);

}

if (a.getAltAccelerators() != null) {

for (KeyStroke k : a.getAltAccelerators()) {

establishKeyBinding(c, a, k);

}

}

}

public static void establishKeyBinding(JComponent c, Action a, KeyStroke key) {

if (key != null) {

InputMap im = c.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

ActionMap am = c.getActionMap();

im.put(key, a.getValue(Action.NAME));

am.put(a.getValue(Action.NAME), a);

}

}

You'd use this like (inside the constructor for your JPanel or whatever):

Utils.establishKeyBinding(this, RefreshAction);

mbmerrilla at 2007-7-12 21:07:55 > top of Java-index,Desktop,Core GUI APIs...
# 3
Thanks a lot for your solutions...Specially mbmerrill , the way you saw is really usefull and it worked ...Thanks again and again...
susthiyaa at 2007-7-12 21:07:55 > top of Java-index,Desktop,Core GUI APIs...