2 Replies Latest reply: Apr 13, 2013 3:52 AM by mh*379860*ly RSS

    Modal dialog covered by other modal dialog

    mh*379860*ly
      HI Gentlemen,

      I have built a Swing application with several JFormattedTextField and JButton entities. It has been working almost perfectly well, but when I fill a SimpleDateFormat("yyyy-mm-dd") field that has a FocusListener with focusLost(), checking the field contents for validity, I have problems. I throw an exception if not OK (MyException), which displays an info dialog window (e g 2001-02-29). My problem is the following: When I hit TAB to jump to the next field - which is a button - the original dialog box is covered by a new one, coming from the button, if it experiences an error in its own (i e another field is not yet filled that is required for the button). This is very annoying--I would like the date field to keep focus until the contents are valid. Please help, I have studied so many articles in the web but none was satisfactory. Thanks, regards

      Miklos HERBOLY
          beginnTemplate.addFocusListener(new FocusListener() {
            public void focusGained(FocusEvent e)  {
              //displayMessage("Focus gained", e);
            }
            public void focusLost(FocusEvent e)  {
              //displayMessage("Focus lost", e);
      
           SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
           sdf.setLenient(false);
       
           try {
                //if not valid, it will throw ParseException
             Date date = sdf.parse(beginnTemplate.getText());
                int year = Integer.parseInt(beginnTemplate.getText().substring(0,4));
                int month = Integer.parseInt(beginnTemplate.getText().substring(5,7));
                int day = Integer.parseInt(beginnTemplate.getText().substring(8,10));
                //System.out.println(year + " leap=" + leapYear(year) + " month=" + month + " day=" + day);
                days[1] = (leapYear(year) ? 29 : 28);          // Setzen Februar
      
                if (month > 12) throw new MyException("Ungültiger Monat"); 
                if (day > days[month - 1]) throw new MyException("Ungültiger Tag");
      
           }
           catch ( MyException ex) { ; }
           catch (Exception ex) {showErrorMessage("Ungültiges Datum"); }
      
      
            }
          });