Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8288031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:11:41+00:00 2026-06-08T12:11:41+00:00

I have an Eclipse JFace Dialog with several Text fields in it. When the

  • 0

I have an Eclipse JFace Dialog with several Text fields in it. When the user presses the . key in a text field, I want it to behave as though the tab key had been pressed and focus sent to the next text field and the . thrown away (think entering an IP address).

How is this best implemented?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:11:42+00:00Added an answer on June 8, 2026 at 12:11 pm

    The following does what you want. Basically it adds KeyListener and FocusListener to the Text widgets and circles through them when . is pressed:

    public class TestClass
    {
        private static int counter = 0;
    
        public static void main(String[] args)
        {
            Display display = Display.getDefault();
            Shell shell = new Shell(display);
    
            shell.setLayout(new FillLayout());
    
            /* These are the text fields */
            final Text textOne = new Text(shell, SWT.BORDER);
            final Text textTwo = new Text(shell, SWT.BORDER);
            final Text textThree = new Text(shell, SWT.BORDER);
    
            /* Save them in an arraylist */
            final ArrayList<Text> textFields = new ArrayList<Text>();
            textFields.add(textOne);
            textFields.add(textTwo);
            textFields.add(textThree);
    
            /* save their position as well (not optimal, you can think of an easier method) */
            final HashMap<Text, Integer> textFieldsMapping = new HashMap<Text, Integer>();
            textFieldsMapping.put(textOne, 0);
            textFieldsMapping.put(textTwo, 1);
            textFieldsMapping.put(textThree, 2);
    
            /* Define keylistener which takes care of using . as tab */
            KeyListener keyListener = new KeyListener() {
    
                @Override
                public void keyReleased(KeyEvent arg0) {
                }
    
                @Override
                public void keyPressed(KeyEvent arg0) {
                    /* if '.' pressed */
                    if(arg0.character == '.')
                    {
                        /* ignore this action */
                        arg0.doit = false;
    
                        /* get next text field */
                        Text next = textFields.get(counter);
    
                        /* force focus on this text field */
                        next.setFocus();
                        next.forceFocus();
                    }
                }
            };
    
            /* Define focuslistener which sets current position */
            FocusListener focusListener = new FocusListener() {
    
                @Override
                public void focusLost(FocusEvent arg0) {
                }
    
                @Override
                public void focusGained(FocusEvent arg0) {
                    /* get current text field */
                    Text current = (Text)arg0.getSource();
    
                    /* get current position */
                    int currentPosition = textFieldsMapping.get(current);
    
                    /* set counter to next text field */
                    counter = (currentPosition + 1) % textFields.size();
                }
            };
    
            /* add keylistener to text fields */
            textOne.addKeyListener(keyListener);
            textTwo.addKeyListener(keyListener);
            textThree.addKeyListener(keyListener);
    
            /* add focuslistener to text fields */
            textOne.addFocusListener(focusListener);
            textTwo.addFocusListener(focusListener);
            textThree.addFocusListener(focusListener);
    
            shell.pack();
            shell.open();
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a My custom Dialog which extends org.eclipse.jface.dialogs.Dialog. But whenever it displays,
I have Eclipse with m2 plugin and want to make new project with Spring.
I have eclipse Galileo 3.5 with maven plugin installed. I want to know if
I have an application that uses org.eclipse.jface.preference.FieldEditorPreferencePage in order to create preference pages. During
I want to show a ProgressBar inside a normal jface Dialog at the start
I am writing jython application with eclipse SWT/JFace. I have to pass float array
I have eclipse and ADT and android SDK installed and I want to test
I have eclipse 3.6, i have installed lot of plugins. But i want to
Is there some way to have Eclipse NOT present the Android Device Chooser dialog
HI all, I have Eclipse installed with PDT (PHP Development tools). I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.