2009-12-16 3 views

답변

-2

나는 onKeyPress 이벤트에 액세스하는 방법을 알고 있다고 가정합니다.

+0

-1. 이것은 아무도 도움이되지 않습니다. – pvorb

4

JFormattedTextField에는 텍스트 필드의 NumberFormatter가 있습니다. 텍스트 영역에서이 작업을 사용하는 것을 실제로 보지 못합니다. 얼마나 큰 부동 소수점 숫자를 기대합니까?

0

당신이 필요에 따라이의 라인을 따라 뭔가 당신을 위해 작동 할 수 있습니다

myTextField.setInputVerifier(new InputVerifier() { 

      @Override 
      public boolean verify(JComponent input) { 
       JTextField textField = ((JTextField) input); 
       try { 

        Float isFloat = Float.valueOf(textField.getText()); 
        textField.setBackground(Color.WHITE); 
        return true; 
       } catch (NumberFormatException e) { 
        textField.setBackground(Color.RED); 
        return false; 
       } 

      } 
     });