Hi,
Google just told me that :
KeyStroke keyStroke = KeyStroke.getKeyStroke("ctrl c");
ActionListener action = table.getActionForKeyStroke( keyStroke );
action.actionPerformed( null );
Regards,
Arnaud
> Hi,
>
[quoted text clipped - 7 lines]
> --
> Message posted via http://www.javakb.com
Marie - 19 Apr 2005 13:49 GMT
Thanks a lot!
I've tried both these two methods and they create an ActionListener that is
not null (it's actually the same), but it doesn't work... When I press the
copy button, it still doesn't copy anything... What am I doing wrong?
KeyStroke keyStroke = KeyStroke.getKeyStroke('C',
java.awt.event.InputEvent.CTRL_MASK);
ActionListener copyAction = table.getActionForKeyStroke(keyStroke);
copyBt.addActionListener(copyAction);
//or
ActionListener copyAction2 = table.getActionMap().get("copy");
copyBt2.addActionListener(copyAction2);
Thanks,
Marie
Marie - 19 Apr 2005 16:38 GMT
For future references, what I did is this:
copyButton.addActionListener(new CopyListener());
class CopyListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == copyButton) {
e.setSource(table); //table is a JTable
ActionListener copyAction2 = table.getActionMap().get("copy");
copyAction2.actionPerformed(e);
}
}
}
And it works great!!!