This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
simple question, I have a jbutton, how do I simulate a button click on that button..nothing in the API seems obvious..I need something like a set Accelerator Method.( I dont want to use Mnemonics)..when the user clicks on the left arrow button on the Keyboard I want to trigger that buttons action. Is there anyway to do this apart from implementing ur own Key Listener for that button? Thanks
wouldnt I still need to listen on that key though?
Kanu
Greenhorn
Joined: Feb 26, 2002
Posts: 1
posted
0
The place where you have created a JButton: JButton jb =new JButton(); jb .addActionListener(this); Then, write a method, public void actionPerformed(ActionEvent ae) { if(ae.getSource()==jb) { //you can type here the cod that you want to write, when the object //gets clicked. } }
Rob Ross
Bartender
Joined: Jan 07, 2002
Posts: 2205
posted
0
Sagar, yes, you have to add a listener to capture the keypress, and in response call the doClick() method of your button.
Remus Stratulat
Greenhorn
Joined: Jan 29, 2002
Posts: 14
posted
0
Here is something that I think will help you. I spent some time looking at BasicButtonListener and BasicButtonUI and come up with this: // setting the to receive action when F3 is pressed InputMap keyMap = new ComponentInputMap(Btn); keyMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), "action"); ActionMap actionMap = new ActionMapUIResource(); actionMap.put("action", new HelpAction()); SwingUtilities.replaceUIActionMap(Btn, actionMap); SwingUtilities.replaceUIInputMap(Btn, JComponent.WHEN_IN_FOCUSED_WINDOW, keyMap); // setting done From now on the button is pressed every time you hit F3, whatever the focused component.
strem
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.