Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

disable tab key and auto edit other textfields

Posted on 2005-03-15
3
Medium Priority
?
919 Views
Last Modified: 2008-01-09
Hi

1. How to disable the tab key in a JtextArea.

2. I have multiple JTextField say tx1,tx2,tx3,tx4.
Once I have enter the tx1 filed, or once my cursor goes to tx2 box, I wud like to auto complete the rest of tx2,tx3,tx4.

Assume that I already have an array of strings[][] to fill up the rest.
0
Comment
Question by:linchong
  • 3
3 Comments
 
LVL 6

Expert Comment

by:durgaprasad_j
ID: 13552883
hi,
did you try this setFocusTraversalKeysEnabled function of JTextArea.

DP
0
 
LVL 6

Accepted Solution

by:
durgaprasad_j earned 600 total points
ID: 13552983
hi,  try this , you have to set FocusTraversalKeys for JTextArea

import javax.swing.*;
import java.awt.*;
import java.util.*;
public class test extends JFrame
{
      public test()
      {
            JPanel jp1=new JPanel();
            this.setSize(new Dimension(400,400));
            JTextArea jta=new JTextArea("adfs adf adsf afd");
            
            jta.setPreferredSize(new Dimension(200,200));
            
            Set set = new HashSet(jta.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
            set.clear();   // Call clear() if you want to eliminate the current key set
            set.add(KeyStroke.getKeyStroke("TAB"));
            jta.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set);
            jp1.add(jta);
            
            JTextArea jta2=new JTextArea("adfs adf adsf afd");
            jta2.setPreferredSize(new Dimension(200,200));
            
            Set set1 = new HashSet(jta2.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
            set1.clear();   // Call clear() if you want to eliminate the current key set
            set1.add(KeyStroke.getKeyStroke("TAB"));
            jta2.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set1);
            
            jp1.add(jta2);
            
            this.getContentPane().add(jp1);
            
            this.setVisible(true);
      }
      public static void main(String args[])
      {
            test a=new test();
      }
}

Hope this helps
0
 
LVL 6

Expert Comment

by:durgaprasad_j
ID: 13572036
:)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question