SHARE
TWEET

Untitled

a guest Aug 26th, 2013 20 Never
  1. public class XXX
  2. {
  3.     public static void main(String args[]) {
  4.         JComponent comp = new JTable(); // some panel or table
  5.         comp.getInputMap().put(KeyStroke.getKeyStroke("F4"), "xxxaction");
  6.         comp..getActionMap().put("xxxaction", new XXXAction());
  7.     }
  8.  
  9.     public class XXXAction extends AbstractAction
  10.     {
  11.         @Override
  12.         public void actionPerformed(ActionEvent e)
  13.         {
  14.              // Something;
  15.         }
  16.     }
  17. }
  18.        
  19. Action action = component.getActionMap().get("...");
  20.  
  21. if (action != null)
  22. {
  23.     ActionEvent ae = new ActionEvent(component, ActionEvent.ACTION_PERFORMED, "");
  24.     action.actionPerformed( ae );
  25. }
RAW Paste Data
Top