Results 1 to 5 of 5
Thread: Key Binding problem
- 06-22-2010, 02:18 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 23
- Rep Power
- 0
Key Binding problem
I am trying to do key binding
this is my code
public Buttons() {
initComponents();
btn1.getInputMap(jPanel1.WHEN_IN_FOCUSED_WINDOW).p ut(KeyStroke.getKeyStroke("ENTER"),"open project");
btn1.getActionMap().put("open project", new actionPerformed());
}
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "You Clicked BTN1");
}
but in the getActionMap where it says new actionPerformed(), Netbeans puts a red line underneath it and on rollover it says
cannot find symbol
symbol: class actionPerformed
location: class Buttons
- 06-22-2010, 02:30 AM #2
Where did you get this code from?
actionPerformed() is the name of the method in the ActionListener interface.
What is supposed to be the second parameter to the put() method?
-
Agrees with Norm -- if you have an error then you should check the API to make sure that your method calls have the right format.
But having said that, if you're trying to trap the enter key to make one JButton the default button, there's an easier way. Please check out JRootPane's setDefaultButton method.
- 06-22-2010, 03:58 AM #4
Member
- Join Date
- Jun 2010
- Posts
- 23
- Rep Power
- 0
I got the key binding code from a forum post and i wrote the actionPerformed function. I wrote a public function for the actionPerformed and tried to use it in the getActionMap(). This is just a small trial, i want to do this to a bunch of buttons and with different keys so i thought i should try and do it to one first.
- 06-22-2010, 03:59 AM #5
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
Similar Threads
-
JAXB Binding
By Fusebox in forum XMLReplies: 0Last Post: 06-11-2010, 10:06 PM -
dynamic binding
By apparao in forum New To JavaReplies: 1Last Post: 02-16-2010, 08:41 AM -
[SOLVED] Key binding Q
By playwin2 in forum New To JavaReplies: 3Last Post: 11-04-2008, 06:04 AM -
Spring binding in jsp
By Pierre Javason in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 05-05-2008, 12:21 PM -
Dynamic Binding
By javarishi in forum New To JavaReplies: 3Last Post: 04-09-2008, 11:17 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks