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

x
?
Solved

focusLost event

Posted on 2004-11-02
3
Medium Priority
?
307 Views
Last Modified: 2012-06-27
Hi,
  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.

thanks
0
Comment
Question by:Bourke
[X]
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
3 Comments
 
LVL 2

Expert Comment

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

Accepted Solution

by:
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();
        field1.addFocusListener(listener);
        field2.addFocusListener(listener);
        b.addFocusListener(listener);
    }
   
    public static void main(String args[]) {
        new MyTextFieldText().show();
    }
   
  class MyFocusListener extends FocusAdapter {
        public void focusGained(FocusEvent evt) {
        if(evt.getSource()!=b)
        {
           if(field1.getText().trim().length()==0)
           {
               field1.requestFocus();
               return;
           }
        }                
        }        
    }
  }
0
 

Author Comment

by:Bourke
ID: 12481126
sudhakar

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
0

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