Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Invoking an action from a MouseListener on a JTable

Reply
Thread Tools

Invoking an action from a MouseListener on a JTable

 
 
Brian J. Sayatovic
Guest
Posts: n/a
 
      07-31-2003
I've got a JTable that I'd like to have invoke an Action when a user
double-clicks on a row. I found code on Google to get me started on
adding a MouseListener to the table, checking the click count and
calculating the clicked row. What I'm stuck on is how to invoke the
action.

My code is in such a way that I do have a reference to the Action
instance readily available. But, to invoke it, I need to call
Action.actionPerformed(ActionEvent). I'm uncertain of how to construct
the ActionEvent.

I've used the MouseEvent's source and id to construct the ActionEvent.
I've used a hard-coded action name for now ("EDIT"). But what about
the modifiers? At this time, I'm not concerned about a keymask, btu I
may be in the future.

The MouseEvent's constants for the key masks from from
java.awt.event.InputEvent constants. But the ActionEvent class defines
its own constants for the key masks. Are these two compatible?

Is there a better way to achieve my end goal of invoking the edit
Action when a row is double-clicked?

Regards,
Brian.
 
Reply With Quote
 
 
 
 
Kleopatra
Guest
Posts: n/a
 
      07-31-2003


"Brian J. Sayatovic" wrote:
>
> I've got a JTable that I'd like to have invoke an Action when a user
> double-clicks on a row. I found code on Google to get me started on
> adding a MouseListener to the table, checking the click count and
> calculating the clicked row. What I'm stuck on is how to invoke the
> action.
>
> My code is in such a way that I do have a reference to the Action
> instance readily available. But, to invoke it, I need to call
> Action.actionPerformed(ActionEvent). I'm uncertain of how to construct
> the ActionEvent.


Most of the time it does not really matter - even passing a null is okay
if you are sure that the action can cope with a null (just try and see
what happens). Though if you are invoking an action from the table's
(or any other component's) actionMap then you'll need to construct a
minimal action that has the sender. Reason is that those actions often
are static and shared and therefore need the sender in the parameter to
do something meaningful. If you are still unsure have a look at doc and
source of SwingUtilities.notifyAction (there it's done for keyStrokes
but can do something close analogous for mouseEvents)


Greetings
Jeanette


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Putting a JTable inside a JTable cell? Tivo Escobar Java 1 04-12-2007 11:09 AM
How to move data from a CSV file to a JTable, and from a JTable to a CSV file ? Tintin92 Java 1 02-14-2007 06:51 PM
Newbie MouseListener Problem Cammy Java 2 04-10-2004 06:34 PM
Weird Problem in using MouseListener Minti Java 2 02-19-2004 07:23 PM
MouseListener and hiding components. Peter the Swede Java 0 11-19-2003 10:57 AM



Advertisments