Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


focusLost event

Posted on 2004-11-02
Medium Priority
Last Modified: 2012-06-27
  I have a JTextField and when focusLost event is triggered it get details from the database and fill the other fields.
So there is a check there to make sure the JTextField is not empty to do so.  That is grand but if focus is on this JTextField and I hit the canel button I get the message the JTextField cannot be empty.

Is there anyway to find out in the FocusLost if the next component to get the focus is a Cancel button?

Or is there another way to do this.

Question by:Bourke
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 12474843
Should the Cancel button be checking if any of the fields are empty if you are just cancelling the form?
LVL 14

Accepted Solution

sudhakar_koundinya earned 150 total points
ID: 12474998
Hope this model might help you

import javax.swing.*;
import java.awt.event.*;
 * MyTextFieldText.java
 * Created on November 2, 2004, 10:49 PM

 * @author  Sudhakar
public class MyTextFieldText extends javax.swing.JFrame {
    JTextField field=new JTextField("field");
    JTextField field1=new JTextField("field1");
    JTextField field2=new JTextField("field2");
    JButton b=new JButton("Cancel");
    public MyTextFieldText() {
       MyFocusListener listener= new MyFocusListener();
    public static void main(String args[]) {
        new MyTextFieldText().show();
  class MyFocusListener extends FocusAdapter {
        public void focusGained(FocusEvent evt) {

Author Comment

ID: 12481126

The code you gave me above is what I have, but it made me re-look at my own code and found I should not have had a Dialog where it should not be.

Thanks for your help

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

636 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