Results 1 to 5 of 5
Thread: Keyboard
- 01-29-2011, 09:34 AM #1
Senior Member
- Join Date
- Apr 2010
- Location
- Dhaka,Bangladesh
- Posts
- 178
- Rep Power
- 0
Keyboard
Hello ,
I am in a problem to use keyboard in my java code.
Java Code:class getkeyboard{ JTextField a=new JTextfield(); JTextField b=new JTextfield(); JFrame frm; InputMap map,map1; KeyStroke key,key1; public getkeyboard(){ frm=new JFrame("Keyboard"); frm.setSize(300,300); cnt=frm.getContentPane(); frm.setLayout(null); a.setBounds(20,20,100,30); a.setBounds(20,70,100,30); key = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, Event.CTRL_MASK); map.put(key, DefaultEditorKit.insertTabAction); } public static void main(String ayu[]){ getkeyboard a=new getkeyboard(); } }
By this when I press ctrl+enter then cursor remains in same textfield with tab.
My problem is when I will press just Enter key then the cursor will go to the next textfield.
How to do that??
Thanks in advance.
Ujjal
Dhaka-Bangladesh
- 01-29-2011, 11:58 AM #2
Member
- Join Date
- Nov 2010
- Location
- New Delhi
- Posts
- 50
- Rep Power
- 0
Dear Ujjal ur code is not complete can u put ur complete code to check out what is the problem.
- 01-29-2011, 12:20 PM #3
Senior Member
- Join Date
- Apr 2010
- Location
- Dhaka,Bangladesh
- Posts
- 178
- Rep Power
- 0
Well,please run this code.You will see two textfield on a JFrame.
I just need that if I press ENTER ,cursor must go to the next TextField.
What I have done in this code is that,if I press ctrl+enter ,there occures a TAB pressing in the same textfield.
If I am not clear to you,then please let me know.Java Code:////////NewClass.java/////// import javax.swing.*; import java.awt.*; import javax.swing.JScrollPane; import javax.swing.JOptionPane; import java.sql.*; import java.util.*; import javax.swing.text.*; import java.awt.event.*; import java.util.Calendar; class getkeyboard{ JTextField a,b; JFrame frm; Container cnt; InputMap map,map1; KeyStroke key,key1; public getkeyboard(){ frm=new JFrame("Keyboard"); cnt=frm.getContentPane(); frm.setLayout(null); a=new JTextField(); b=new JTextField(); frm.add(a); frm.add(b); a.setBounds(20,20,100,30); b.setBounds(20,70,100,30); map = a.getInputMap(); key = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, Event.CTRL_MASK); map.put(key, DefaultEditorKit.insertTabAction); frm.setVisible(true); frm.setSize(300,300); } } public class NewClass{ public static void main(String ayu[]){ try{ getkeyboard adfdf=new getkeyboard(); }catch(Exception e){} } }Last edited by UJJAL DHAR; 01-29-2011 at 12:24 PM.
- 01-29-2011, 01:34 PM #4
Member
- Join Date
- Nov 2010
- Location
- New Delhi
- Posts
- 50
- Rep Power
- 0
How to Use Key Bindings (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Other Swing Features)
i think this link will be helpful for u.
- 01-29-2011, 02:26 PM #5
Senior Member
- Join Date
- Apr 2010
- Location
- Dhaka,Bangladesh
- Posts
- 178
- Rep Power
- 0
Similar Threads
-
Keyboard not working
By Robotuner in forum New To JavaReplies: 0Last Post: 10-27-2009, 07:51 PM -
[Virtual KeyBoard] - Anybody know ?
By Matheus Leandro Ferreira in forum Advanced JavaReplies: 1Last Post: 09-30-2009, 08:22 PM -
KeyBoard Problem
By arimakidd in forum Java AppletsReplies: 3Last Post: 09-19-2008, 04:05 PM -
Reading Keyboard
By ushigley in forum New To JavaReplies: 4Last Post: 08-20-2008, 01:50 PM -
Help with keyboard events?
By Bibendum in forum New To JavaReplies: 2Last Post: 11-02-2007, 02:51 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks