Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2005

Tip: Looking for answers? Try searching our database.

Copy from Jtable

Thread view: 
Marie - 18 Apr 2005 19:20 GMT
Hi,

I am able to copy from a JTable using CTRL-C. I didn't do anything about
that. I would like to know what method is called when I press CTRL-C so I
can call this method when I select Edit-Copy in my menu bar.

Thanks,
Marie
Arnaud Berger - 19 Apr 2005 07:27 GMT
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!!!


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.