views:

17

answers:

1

I Have a JButton (or any Component, really) that I would like to trick into thinking that it has been clicked on and therefore firing its action performed event. I don't want to call the action performed or doClick directly because I am trying to make a solution that generalizes beyond buttons, and I am constrained to posting events.

I would have thought that posting a MousePressed event to the system event queue would have done it, but no. ( with appropriate location, click count etc.)

Then I thought a mouse entered followed by a mouse move, a mouse pressed, a mouse released, and a mouse clicked, but no.

None of this causes the JButton to fire its action performed like it does when I actually click on it.

Has anyone caused a JButton to spit out its action performed event by driving it with mouse events? Moved a JSlider with mouse events? Expanded a tree node?

Thanks for any help.

+1  A: 

Have you tried the fireActionPerformed method? I can't off the top of my head now remember if all components have it but if i remember right, all buttons and menu items should deifnately have it. Just a thought

robinsonc494
`fireActionPerformed` is `protected`, so you would need to expose it in a subclass.
akf
you would have to since only classes in the same package or a subclass would be able to use it. How you go about implementing the rest is all up to you. Its not a common thing and i've certainly never done it i just assumed it would work based on what the javadocs say
robinsonc494