aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes how to simulate a button click Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to simulate a button click" Watch "how to simulate a button click" New topic
Author

how to simulate a button click

Brian Percival
Ranch Hand

Joined: Jun 23, 2004
Posts: 163
I have a JButton, which has a setActionCommand and setActionListener.
When I click on the button the event is generated and is handled by the actionListener.
How can I generate the event programmatically as if the button is really pressed?


regards,
Brian
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
button.doClick();

an alternative is to move the code from actionPerformed into a separate method
and call the method from actionPerformed(). You can then call the same method
from other parts of the program.
Brian Percival
Ranch Hand

Joined: Jun 23, 2004
Posts: 163
My actual problem was, to access the local file system in an applet. I found the code on the net, signed it and it works fine. But when I do the equivalent of what the code si doing in my own public method, creating new file and all, I get a permission denied exception. Any pointers regarding this?

doClick is raising the event. However, the security system is somehow aware of the execution comes to the actionPerformed().

When I do a click on the browser, the file is accessed fine. But when I do it thru a doClick call in my public method, I get a permission denied exception. Smart!! But what is the workaround??

regards,
Brian
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to simulate a button click