Results 1 to 3 of 3
  1. #1
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default Cursor controlling?

    I am stuck in a simple problem.Please anyone help me.


    I am giving a simple code.After run the code two JTextField appear in a JFrame.After writing something,pressing ENTER,the text will be displayed.


    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;
     
    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);
    
    a.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
    
                       System.out.println(a.getText());
    
        }}
    );
    
    b.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
    
                       System.out.println(b.getText());
    
        }}
    );
    
    
    
    
    
    
     
       frm.setVisible(true);
     frm.setSize(300,300);
    }
    }
    
    public class NewClass{
    public static void main(String ayu[]){
    try{
    getkeyboard adfdf=new getkeyboard();
    }catch(Exception e){}
     }
    }



    But, I am in a need of that when I press ENTER in a JTEXTFIELD,the cursur should go to the next JTextField [like pressing the TAB]

    How to do that??

  2. #2
    Junky's Avatar
    Junky is online now Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,758
    Rep Power
    7

    Default

    requestFocus() or requestFocusInWindow()

  3. #3
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

Similar Threads

  1. Controlling cmd from java...HELP!!
    By eponcedeleon in forum Advanced Java
    Replies: 12
    Last Post: 02-23-2010, 06:33 PM
  2. change the mouse cursor - crosshair cursor
    By cassysumandak in forum New To Java
    Replies: 1
    Last Post: 09-28-2009, 01:57 AM
  3. Controlling the running os process
    By Muralidharan in forum Threads and Synchronization
    Replies: 1
    Last Post: 03-26-2009, 07:03 AM
  4. Controlling loop using next button
    By cassysumandak in forum New To Java
    Replies: 25
    Last Post: 03-22-2009, 03:04 PM
  5. controlling GC
    By ravian in forum Eclipse
    Replies: 2
    Last Post: 01-03-2008, 08:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •