Solved

Why the JOptionPane show 2 time?

Posted on 2002-05-07
10
601 Views
Last Modified: 2012-06-21
Hai, now i try to develope the TextFieldcomponent,
Here is my code;

My question is why after the textfield has been lostFocus,
should show the JOptionMessage, but why it show two time?
beside that , still got a lot problem need to improve....

got any example? This component is one textfield that accept the date input and validate it.


public class DateTextField extends JTextField{    
  DateTextField(int cols){
    super(cols);
    addFocusListener(new FocusAdapter(){
      public void focusLost(FocusEvent e){
        String fieldText = getText();
     SimpleDateFormat simpleDateFormat = new
                         SimpleDateFormat("dd/MM/yyyy");
        Date date = null;
     if(fieldText.equals(""))
       return;
     try{
       date = simpleDateFormat.parse(fieldText);
       fieldText = simpleDateFormat.format(date);
     } catch (ParseException pe){
       pe.printStackTrace();
       fieldText = "";
       showMessage();
       requestFocus();
     }
     setText(fieldText);
     }
     });
  }
  private void showMessage(){
    JOptionPane.showMessageDialog(get(),"Input
        Date", "Invalid Filed",JOptionPane.ERROR_MESSAGE);
  }

}
0
Comment
Question by:HSL
  • 6
  • 4
10 Comments
 
LVL 92

Expert Comment

by:objects
Comment Utility
I'd sya that its appearing twice cause your field is recieving two focus lost events.
Looks like it'd get one when the text field loses focus, at which point you request a popup dialog and return focus to text field. Then another after that dialog pops up and takes focus.
0
 

Author Comment

by:HSL
Comment Utility
Ya, i also think like this, then how i solve this problem?
Thanks
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
Try removing the requestFocus() call.
0
 

Author Comment

by:HSL
Comment Utility
Ya, i also think like this, then how i solve this problem?
Thanks
0
 

Author Comment

by:HSL
Comment Utility
Hmm....This one i try before , but also cannot,
still got any solution?

is it i need to restructure ? Thanks...
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:HSL
Comment Utility
Hmm....This one i try before , but also cannot,
still got any solution?

is it i need to restructure ? Thanks...
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
WHy can't you remove the requestFocus method??
0
 

Author Comment

by:HSL
Comment Utility
Sorry.... what i mean is i remove it already...
but the result still same..
The pane still prompt two time.. =)
0
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
Comment Utility
Maybe cause you're it's still in the process of handling the first focusLost, when you pop up the dialog then another one gets queued.
You need to rethink your aproach I think, or track when the dialog is showing. You're current approach will also pop up new dialog every time you lose focus and the data is incorrect so you could end up with LOTS of dialogs.
0
 

Author Comment

by:HSL
Comment Utility
hi, actually this not the actual answer, but now i solve it already , i just want to close this question !
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mergeTwo  challenge 13 71
Updating Java 9 86
ArrayLists in ArrayLists/HashMaps? 4 39
solarwind tftp server 2 30
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now