how to move curosr from one text field to another automatically when the first textfield reaches its maximum length

Ads
 

how to move curosr from one text field to another automatically when the first textfield reaches its maximum length

how to move curosr from one text field to another automatically when the first textfield reaches its maximum length

View Answers

December 11, 2010 at 3:33 PM

Hi Friend,

Here we have created a program where if the user exceeds the limit of six characters in the first text filed, then the cursor automatically moved to the second one.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class MoveCursor{
    public static void main(String[]args){
     JLabel lab1=new JLabel("Name");
     JLabel lab2=new JLabel("Address");
     final JTextField text1=new JTextField(20);
     final JTextField text2=new JTextField(20);
     JPanel p=new JPanel(new GridLayout(2,2));
     JFrame f=new JFrame();
     p.add(lab1);
     p.add(text1);
     p.add(lab2);
     p.add(text2);
     f.add(p);
     f.setVisible(true);
     f.pack();
     text1.addKeyListener(new KeyAdapter(){
          public void keyPressed(KeyEvent e){
          String value=text1.getText();
          if(value.length()==5){
          text2.requestFocus();
            }
          }
     });
    }
    }

Thanks

Ads









Related Tutorials/Questions & Answers:
automatically move next page when data fetched from database is stored in text field
automatically move next page when data fetched from database is stored in text... are stored in database wherein when the in the first text field the data is already stored when data in second text is tried to enter or automaticaaly fetched
how to move records from one table to other based on its creation time
how to move records from one table to other based on its creation time  Hi all,, As part of my requirement ,the records in one table have to move... not be present in first table after creation of two days,and it has to move
Advertisements
how to output text from comboBox from first frame to textField on the second frame? please help me.. thank you in advance..
how to output text from comboBox from first frame to textField on the second frame? please help me.. thank you in advance..  how to output text from comboBox from first frame to textField on the second frame? please help me
How to forward the control from one jsp to another?
How to forward the control from one jsp to another?  Hi... other.i.e. First JSP is communicating with the second JSP, Second JSP is not communicate with the Third JSP. I want forward the control from first jsp to second
How to navigate from one jsf to another in eclipse
How to navigate from one jsf to another in eclipse  Hi there is my jsf code... <%@ page language="java" contentType="text/html; charset... is working fine in NETBEANS.. but when i run this in eclipse it stays on the first
how to pass a string from one class to another
how to pass a string from one class to another  hi all, Good morning... string from one class to another. import java.util.*; class A{ static String... string from one class to another. import java.io.*; class Class1 { public
How to prevent from navigating to ck buttonnext page when user reaches login page using back button
How to prevent from navigating to ck buttonnext page when user reaches login... 2)Page with link to open pdf files When i lo-gin,it takes me to 2nd page where there are buttons that opens pdf files in new window.The problem is when i
how to move pointer in Textfield to newline
how to move pointer in Textfield to newline  consider my case...; class Table1 extends Frame implements ActionListener{ TextField tf1,tf2,tf3...(100,10,200,30); Label l2=new Label("Enter the value to get its Table
how to copy file from one directory to another in java with examples
how to copy file from one directory to another in java with examples  how to copy file from one directory to another in java with examples? I want... copy from one directory to another in java. Thanks
how to highlight the field in image,when i have entered into that corresponding field's textbox-any one help out
how to highlight the field in image,when i have entered into that corresponding field's textbox-any one help out  how to highlight the field in image,when i have entered into that corresponding field's textbox. Here webpage
How to pass variable from one class to another in java
How to pass variable from one class to another in java  How to pass variable from one class to another in java?   Example: public class...() { System.out.println("Welcome in " + name + " Its id number : " + IdNo); } public
Copy data from one JTextField to another JTextField
, you will learn how to copy the data from one JTextField into another... Copy data from one JTextField to another JTextField... data into first text field (cell1). Highlight all the text in first cell
How to make a servlet to automatically call another servlet at some time instant.
How to make a servlet to automatically call another servlet at some time instant.  Can some one assist me How to make a servlet to automatically call another servlet at some time instant. currently I have a single servlet which
how to write function of copy from one to another location in this code
how to write function of copy from one to another location in this code  I need to write a code to copy a file from one location to another using browse button in it. i have written code for the browse button. please help me
How To Pass data from one GUI to another in java swing
How To Pass data from one GUI to another in java swing  I'm new to java and part of our assignment is to build a GUI and display a result set from data input. I'm stuck at how to get the user's input from JTextFields and combobox
how to use one form out of multiple form from one jsp to another jsp
how to use one form out of multiple form from one jsp to another jsp  Hi All. please give me your valuable advise for below requirement.. I have... one form from abc.jsp as it is to another .jsp(say def.jsp).Your advise
textfield selected text
textfield selected text  How to select text in text field
update one table from another table
update one table from another table  hello, i need to update one.... for example TotalQuantity field from Products table should be updated if i enter the Quantity field in table 'Products_Purchased'In table 'Products' one item
how to use string of one class into another Class
how to use string of one class into another Class  I created textField(JTextField t1=new JTextField();(it is in ClassA. The input of this textField i.e t1.getText() is to be used in different(another Class say in ClassB. How can
how to scrape the data from one website another website using html dom parsing in php
how to scrape the data from one website another website using html dom parsing in php  " how to scrape the data from one website another website using html dom parsing in php" i'm trying this one .please provide code for me
passing data from one jframe to another
passing data from one jframe to another  I have two JFrame,built by using the GUI Editor netbeans 6.9.i have to pass a data from a Jtextfield in the first Jframe to another JLabel in the other JFrame.Can you please help me,how
take data from one table and insert same in another
take data from one table and insert same in another  I want to know when a new field update in table and the same data has to update in another table
calling one jsp from another jsp page
calling one jsp from another jsp page  need coding for calling one jsp from another jsp including the xml file.Its urgent
how can retrieve more than one values in text field using ajax?
how can retrieve more than one values in text field using ajax?  im... first then in mysql db retrieve seat numbers 1,2,3,4 in text boxes problem...($result)) { echo "<input name='seat' type='text' value=".$row['Seat_Number
JMF: How trigger event when player reaches certain time playing a video?
JMF: How trigger event when player reaches certain time playing a video?  How to code in Java (with Java Media Framework): When the player reaches a certain time playing a video clip (for example, reaching 3.124 minutes
How to solve concurrency issue when an application is running on two machine to fetch record from one database
How to solve concurrency issue when an application is running on two machine to fetch record from one database  I have developed an application in java to run on two machines. Program will fetch a record from database and process
How can java programs execute automatically when it connects to network
How can java programs execute automatically when it connects to network  Good Day dears... How can java programs execute automatically when it connects to network. Thanks in Advance friends Shackir   How can i Test
how to enable textfield in j2me netbeans when a choice element is selected?
how to enable textfield in j2me netbeans when a choice element is selected?  How to enable a textfield in j2me using netbeans when a choice element is selected and how to keep it disabled when any choice element corresponding
how to enable textfield in j2me netbeans when a choice element is selected?
how to enable textfield in j2me netbeans when a choice element is selected?  How to enable a textfield in j2me using netbeans when a choice element is selected and how to keep it disabled when any choice element corresponding
File copy from one directory to another in java
File copy from one directory to another in java  I am trying to find very good code example for copying a file from one directory to another... from a directory to another directory. How to achieve this? Is there any API
to bring checked data from one page to another
to bring checked data from one page to another  thanks for your help... there is one jsp page , on it there is a link, on click of which it is opening second... fetching data from the database on second jsp page with checkbox corresponding each

Ads