Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Aug 26th, 2013  |  syntax: None  |  size: 0.64 KB  |  views: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data