jtextfield - Arrow Keys, TextField focus in java? -


I have JPanel 16 in jtextfield (4x4), I I am using them for loop.

Now, I want to use my arrow key to focus from this jtextfield to second.

How can I do this?

Code (Extracted from the reply to OP)

  Private JTextField [] characters; Public Zero Drawing () {pnlWords.removeAll (); pnlWords.setLayout (new grid layout (4, 4)); Character = new JTextField [4 * 4]; For (int i = 0; i <4 * 4; i ++) {character [i] = new JTextField (); Character [i] .setHorizontalAlignment (JLabel.CENTER); Character [i] .setBackground (Color.LIGHT_GRAY); Character [i] .setFont (font); Characters [i] .addKeyListener (new Java.Awt.event.KeyAdapter () {Public Zero Key was typed (java.awt.event.KeyEvent evt) {lettersKeyTyped (evt);}}); PnlWords.add (letter [i]); }} Public Zero Character Insect (java.awt.event.KeyEvent evt) {int key = evt.getKeyCode (); For (int i = 0; i <4 * 4; i ++) {switch (key) {case of event VK_LEFT: Characters [i - 1] .requestFocus (); break; CaseyWell VK_RiGHT: Characters [i + 1] .requestFocus (); break; Case event. VK_UP: Characters [i-4] .requestFocus (); break; Case KeyEvent.VK_DOWN: Characters [i + 4] .requestFocus (); break; }}}}    

You can create an array on all your JTextFields and a KeyAdapter Panel If the entered key is the right key, set the focus on the next JTextField in the array. If this is the left key, set the focus on the previous JTextField. Consider the difference between preincrement and postininkment.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -