2013-10-25 26 views
0

我希望JFormattedTextField接受任何大於0的小數,但我無法弄清楚如何使用DecimalFormat類來完成此操作?有關格式化文本字段的兩個問題

此外,我已將我的文本字段限制爲10列。當我以編程方式設置一個數字超過10位數字(1.333 ...)時,文本字段顯示向右滾動,這樣它只顯示10 3s,「3333333 ...」。我希望它顯示爲向左滾動,以便顯示前10位數字「1.333 ...」如何強制顯示時向左滾動顯示的任何建議?

回答

0

使用MaskFormatter將幫助您限制文本字段以允許最多10位數字。

 try {   
      MaskFormatter format = new MaskFormatter(""); 
      // Allows you to enter any digit greater than 0. 
      format.setInvalidCharacters("0"); 
      JFormattedTextField inputField = new JFormattedTextField(format); 

      // Add FocusListener and onFocusLost set the caret position to the zeroth position. 
      inputField.setCaretPosition(0); 
     } catch (ParseException e) { 
      e.printStackTrace(); 
     } 
+0

不是真的我在問什麼。我問如何限制字段爲小數> 0,以及如何顯示字段顯示時最左邊的數字。用戶可以輸入無限數字,10列工作,一次只顯示10位數字。 – ab11

+0

更新了答案。希望這可以幫助 !!! – Reji