I've created a JButton and a Jtextfield in java swing. I want the button to perform the same function as BackSpace key of the keyboard. Is there any means to assign the properties of the the BckSpace key to the button, i.e. inheriting the properties of the key.
1bung100
-3
Newbie Poster
Recommended Answers
Jump to PostFollow this link
http://stackoverflow.com/questions/2596641/simulate-backspace-key-with-java-awt-robotrobot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_BACK_SPACE); robot.keyRelease(KeyEvent.VK_BACK_SPACE); robot.keyRelease(KeyEvent.VK_SHIFT);
Jump to PostThat seems like a lot of work to me.
Put an actionListener on your button, and add the code...myfield.setText (myfield.getText ().substring (0, myfield.getText ().length () - 1));
All 5 Replies
Zetlin
11
Junior Poster in Training
Majestics
84
Posting Pro
1bung100
-3
Newbie Poster
hfx642
Kubu Letuka
commented:
Sweet
+0
Kubu Letuka
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.