JavaTM 2
Platform
Std. Ed. v1.4.0

javax.swing.text
$B%/%i%9(J MaskFormatter

java.lang.Object
  |
  +--javax.swing.JFormattedTextField.AbstractFormatter
        |
        +--javax.swing.text.DefaultFormatter
              |
              +--javax.swing.text.MaskFormatter
$B$9$Y$F$N
Cloneable, Serializable

public class MaskFormatter
extends DefaultFormatter

MaskFormatter $B$OJ8;zNs$N%U%)!<%^%C%H$*$h$SJT=8$K;HMQ$5$l$^$9!#(JMaskFormatter $B$NF0:n$O(J Document $B%b%G%k$NFCDj$N0LCV$K$"$kM-8z$JJ8;z$r;XDj$9$k(J String $B%^%9%/7PM3$G@)8f$5$l$^$9!#0J2<$NJ8;z$r;XDj$G$-$^$9!#(J
# $BG$0U$NM-8z$J?t;z!#(JCharacter.isDigit $B$r;HMQ$9$k(J
' $B%(%9%1!<%WJ8;z!#FC
U $BG$0U$NJ8;z(J (Character.isLetter)$B!#$9$Y$F$N>.J8;z$OBgJ8;z$K%^%C%T%s%0$5$l$k(J
L $BG$0U$NJ8;z(J (Character.isLetter)$B!#$9$Y$F$NBgJ8;z$O>.J8;z$K%^%C%T%s%0$5$l$k(J
A $BG$0U$NJ8;z$^$?$O?t;z(J (Character.isLetter $B$^$?$O(J Character.isDigit)
? $BG$0U$NJ8;z(J (Character.isLetter)
* $B$9$Y$F$NJ8;z$*$h$S?t;z(J
H $BG$0U$N(J 16 $B?J?tJ8;z(J (0-9$B!"(Ja-f $B$^$?$O(J A-F)

$BDL>o!"J8;z$O(J 1 $B$D$N(J char $B$KBP1~$7$^$9$,!"0lIt$N8@8l$G$O$3$l$OEv$F$O$^$j$^$;$s!#%^%9%/$OJ8;z$4$H$K0[$J$j!"I,MW$JB?$/$N(J char $B$KE,1~$9$k$h$&D4@0$5$l$^$9!#(J

setInvalidCharacters $B$H(J setValidCharacters $B%a%=%C%I$GF~NO2DG=$JJ8;z$r>\:Y$K8BDj$G$-$^$9!#(JsetInvalidCharacters $B$G$O$I$NJ8;z$,IT@5$+$r;XDj$G$-$^$9!#$^$?(J setValidCharacters $B$G$O$I$NJ8;z$,M-8z$+$r;XDj$G$-$^$9!#$?$H$($P!"0J2<$N%3!<%I%V%m%C%/$OL58z$^$?$OM-8z$JJ8;z$r;}$?$J$$!V(J0xHHH$B!W$N%^%9%/$HEy$7$/$J$j$^$9!#(J

 MaskFormatter formatter = new MaskFormatter("0x***");
 formatter.setValidCharacters("0123456789abcdefABCDEF");
 

$BJ8;zNs$ND9$5$,%^%9%/$ND9$5$h$jC;$$>l9g$KCM$r:G=i$K%U%)!<%^%C%H$9$k$H$-!"%W%l!<%9%[%k%@J8;zNs$,;HMQ$5$l$k$+!"$^$?$O%W%l!<%9%[%k%@J8;z$,;HMQ$5$l$^$9!#M%@h=g0L$O%W%l!<%9%[%k%@J8;zNs$K$"$j$^$9!# MaskFormatter formatter = new MaskFormatter("###-####"); formatter.setPlaceholderCharacter('_'); formatter.getDisplayValue(tf, "123");

$B7k2L$OJ8;zNs!V(J123-____$B!W$K$J$j$^$9!#(JsetPlaceholder("555-1212") $B$,8F$S=P$5$l$?>l9g!"7k2L$O!V(J123-1212$B!W$H$J$j$^$9!#%W%l!<%9%[%k%@(J String $B$O=i4|%U%)!<%^%C%H$K$@$1;HMQ$5$l!"$=$N8e$N%U%)!<%^%C%H$G$O%W%l!<%9%[%k%@J8;z$@$1$,;HMQ$5$l$^$9!#(J

MaskFormatter $B$,M-8z$JJ8;z$@$1$r5v2D$9$k$h$&$K9=@.$5$l$F$$$k>l9g(J (setAllowsInvalid(false))$B!"JT=8;~$K$OI,MW$K1~$8$F%j%F%i%kJ8;z$,%9%-%C%W$5$l$^$9!#%^%9%/!V(J###-####$B!W$*$h$S8=:_CM!V(J555-1212$B!W$rJ];}$9$k(J MaskFormatter $B$r9M$($F$_$^$7$g$&!#1&Lp0u%-!<$r;HMQ$7$F%U%#!<%k%I$r%J%S%2!<%H$9$k$H!"0J2<$N$h$&$K$J$j$^$9(J (| $B$O%-%c%l%C%H$N0LCV(J)$B!#(J

   |555-1212
   5|55-1212
   55|5-1212
   555-|1212
   555-1|212
 
$B!V(J-$B!W$OJT=8IT2DG=$J%j%F%i%kJ8;z$G!"%9%-%C%W$5$l$^$9!#(J

$BJT=8;~$K$O7k2L$H$7$FF1MM$NF0:n$,H/@8$7$^$9!#>e$NNc$N(J MaskFormatter $B$KJ8;zNs!V(J123-45$B!W$H!V(J12345$B!W$rA^F~$9$k>l9g$r9M$($F$_$^$7$g$&!#N>J}$rA^F~$9$k$H!"7k2L$H$7$FF1$8(J String (I"123-45__(I#$B$K$J$j$^$9!#J8;z0LCV(J 3 ($B!V(J-$B!W(J) $B$G(J MaskFormatter $B$,A^F~=hM}$r9T$&$H!"(J2 $B$D$N$3$H$,5/$3$j$^$9!#(J

  1. $BA^F~$5$l$?J8;z$,!V(J-$B!W$N>l9g$O$BA^F~$5$l$?J8;z$,l9g!"?7$7$$0LCV$G$B$=$l0J30$NJ8;z$,A^F~$5$l$k$H!"L58z$JJT=8$H$J$k(J

$B%G%U%)%k%H$G$O(J MaskFormatter $B$OL58z$JJT=8$r5v2D$7$^$;$s$,!"(JsetAllowsInvalid $B%a%=%C%I$r;HMQ$9$k$HJQ99$G$-$^$9!#$3$N>l9g!"M-8z$JJT=8$H$7$FJT=8FbMF$r%3%_%C%H$G$-$^$9(J ($BJQ99$K$O(J setCommitsOnValidEdit $B$r;HMQ(J)$B!#(J

$B%G%U%)%k%H$G$O!"(JMaskFormatter $B$O>e=q$-%b!<%I$G$9!#$D$^$jJ8;z$,F~NO$5$l$k$H!"?75,J8;z$,A^F~$5$l$k$N$G$O$J$/!"8=:_0LCV$NJ8;z$,?75,$KF~NO$5$l$?J8;z$KCV$-49$o$j$^$9!#$3$NF0:n$O(J setOverwriteMode $B%a%=%C%I$GJQ99$G$-$^$9!#(J

$B7Y9p(J: $B$3$N%/%i%9$ND>Ns2=$5$l$?%*%V%8%'%/%H$O!":#8e$N(J Swing $B$N%j%j!<%9$H$O8_49@-$r;}$A$^$;$s!#8=:_$ND>Ns2=%5%]!<%H$O!"C;4|4V$N1?MQ$d!"F1$8%P!<%8%g%s$N(J Swing $B$rTM $B$ND94|1?MQ%5%]!<%H$,!"(J java.beans $B%Q%C%1!<%8$KDI2C$5$l$^$7$?!#(JXMLEncoder $B$r;2>H$7$F$/$@$5$$!#(J

$BF3F~$5$l$?%P!<%8%g%s(J:
1.4

$B%3%s%9%H%i%/%?$N35MW(J
MaskFormatter()
          $B%^%9%/$r;}$?$J$$(J MaskFormatter $B$r:n@.$7$^$9!#(J
MaskFormatter(String mask)
          $B;XDj$7$?%^%9%/$r;}$D(J MaskFormatter $B$r:n@.$7$^$9!#(J
 
$B%a%=%C%I$N35MW(J
 String getInvalidCharacters()
          $BF~NO$,L58z$JJ8;z$rJV$7$^$9!#(J
 String getMask()
          $B=q<0$r@_Dj$9$k%^%9%/$rJV$7$^$9!#(J
 String getPlaceholder()
          $BCM$,%^%9%/$r40A4$KKd$a$F$$$J$$>l9g$K;HMQ$9$k(J String $B$rJV$7$^$9!#(J
 char getPlaceholderCharacter()
          $BCM$K$O$J$$J8;z(J ($B$D$^$j%f!<%6$,F~NO$9$kI,MW$N$"$kJ8;z(J) $B$NBe$o$j$K;HMQ$9$kJ8;z$rJV$7$^$9!#(J
 String getValidCharacters()
          $BF~NO2DG=$JM-8zJ8;z$rJV$7$^$9!#(J
 boolean getValueContainsLiteralCharacters()
          stringToValue $B$,%^%9%/$N%j%F%i%kJ8;z$rJV$9>l9g!"(Jtrue $B$,JV$5$l$^$9!#(J
 void install(JFormattedTextField ftf)
          DefaultFormatter $B$rFCDj$N(J JFormattedTextField $B$K%$%s%9%H!<%k$7$^$9!#(J
 void setInvalidCharacters(String invalidCharacters)
          $BF~NO2DG=$JJ8;z$N>\:Y$J8BDj$,$G$-$^$9!#(J
 void setMask(String mask)
          $BE,@5$JJ8;z$r5,Dj$9$k%^%9%/$r@_Dj$7$^$9!#(J
 void setPlaceholder(String placeholder)
          $BCM$,%^%9%/$r40A4$KKd$a$F$$$J$$>l9g$K;HMQ$9$kJ8;zNs$r@_Dj$7$^$9!#(J
 void setPlaceholderCharacter(char placeholder)
          $BCM$K$O$J$$J8;z(J ($B$D$^$j%f!<%6$,F~NO$9$kI,MW$N$"$kJ8;z(J) $B$NBe$o$j$K;HMQ$9$kJ8;z$r@_Dj$7$^$9!#(J
 void setValidCharacters(String validCharacters)
          $BF~NO2DG=$JJ8;z$r>\:Y$K8BDj$G$-$^$9!#(J
 void setValueContainsLiteralCharacters(boolean containsLiteralChars)
          true $B$N>l9g!"La$jCM$H@_DjCM$O$H$b$K%^%9%/$K%j%F%i%kJ8;z$r;}$A$^$9!#(J
 Object stringToValue(String value)
          $B%F%-%9%H$r2r@O$7$F!"(JString value $B$NE,@Z$J(J Object $BI=8=$rJV$7$^$9!#(J
 String valueToString(Object value)
          $B%^%9%/$K4p$E$$$?(J Object value $B$N(J String $BI=8=$rJV$7$^$9!#(J
 
$B%/%i%9(J javax.swing.text.DefaultFormatter $B$+$i7Q>5$7$?%a%=%C%I(J
clone, getAllowsInvalid, getCommitsOnValidEdit, getDocumentFilter, getNavigationFilter, getOverwriteMode, getValueClass, setAllowsInvalid, setCommitsOnValidEdit, setOverwriteMode, setValueClass
 
$B%/%i%9(J javax.swing.JFormattedTextField.AbstractFormatter $B$+$i7Q>5$7$?%a%=%C%I(J
getActions, getFormattedTextField, invalidEdit, setEditValid, uninstall
 
$B%/%i%9(J java.lang.Object $B$+$i7Q>5$7$?%a%=%C%I(J
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

$B%3%s%9%H%i%/%?$N>\:Y(J

MaskFormatter

public MaskFormatter()
$B%^%9%/$r;}$?$J$$(J MaskFormatter $B$r:n@.$7$^$9!#(J


MaskFormatter

public MaskFormatter(String mask)
              throws ParseException
$B;XDj$7$?%^%9%/$r;}$D(J MaskFormatter $B$r:n@.$7$^$9!#(Jmask $B$,L58z$J%^%9%/$N>l9g!"(JParseException $B$,%9%m!<$5$l$^$9!#(J

$BNc30(J:
ParseException - $B%^%9%/$KM-8z$J%^%9%/J8;z$,$J$$>l9g(J
$B%a%=%C%I$N>\:Y(J

setMask

public void setMask(String mask)
             throws ParseException
$BE,@5$JJ8;z$r5,Dj$9$k%^%9%/$r@_Dj$7$^$9!#(Jmask $B$,M-8z$G$J$$>l9g!"(JParseException $B$,%9%m!<$5$l$^$9!#(J

$BNc30(J:
ParseException - $B%^%9%/$KM-8z$J%^%9%/J8;z$,$J$$>l9g(J

getMask

public String getMask()
$B=q<0$r@_Dj$9$k%^%9%/$rJV$7$^$9!#(J

$BLa$jCM(J:
$BE,@5$JJ8;z$NCM$r5,Dj$9$k%^%9%/(J

setValidCharacters

public void setValidCharacters(String validCharacters)
$BF~NO2DG=$JJ8;z$r>\:Y$K8BDj$G$-$^$9!#%^%9%/$G;XDj$5$l$?J8;z!"(JinvalidCharacters $B$G;XDj$5$l$F$$$J$$J8;z!"$=$7$F(J validCharacters $B$G;XDj$7$?J8;z$@$1$rF~NO$G$-$^$9!#(Jnull $B$rEO$9(J ($B%G%U%)%k%H(J) $B$H$$$&$3$H$O!"M-8z$JJ8;z$,%^%9%/$dL58z$JJ8;z$K$h$C$F$@$1%P%$%s%I$5$l$F$$$k$3$H$rI=$7$^$9!#(J

$B%Q%i%a!<%?(J:
validCharacters - null $B0J30$N>l9g!"E,@5$JJ8;z$r;XDj$9$k(J

getValidCharacters

public String getValidCharacters()
$BF~NO2DG=$JM-8zJ8;z$rJV$7$^$9!#(J

$BLa$jCM(J:
$BE,@5$JJ8;z(J

setInvalidCharacters

public void setInvalidCharacters(String invalidCharacters)
$BF~NO2DG=$JJ8;z$N>\:Y$J8BDj$,$G$-$^$9!#(JinvalidCharacters $B$G$O$J$/!"%^%9%/$d(J validCharacters $B$G;XDj$7$?J8;z$@$1$rF~NO$G$-$^$9!#(Jnull $B$rEO$9(J ($B%G%U%)%k%H(J) $B$H$$$&$3$H$O!"M-8z$JJ8;z$,%^%9%/$dL58z$JJ8;z$K$h$C$F$@$1%P%$%s%I$5$l$F$$$k$3$H$rI=$7$^$9!#(J


getInvalidCharacters

public String getInvalidCharacters()
$BF~NO$,L58z$JJ8;z$rJV$7$^$9!#(J

$BLa$jCM(J:
$BIT@5$JJ8;z(J

setPlaceholder

public void setPlaceholder(String placeholder)
$BCM$,%^%9%/$r40A4$KKd$a$F$$$J$$>l9g$K;HMQ$9$kJ8;zNs$r@_Dj$7$^$9!#(Jnull $BCM$O%W%l!<%9%[%k%@(J char $B$r;HMQ$9$k$3$H$rI=$7$^$9!#(J

$B%Q%i%a!<%?(J:
placeholder - $BCM$,%^%9%/$r40A4$KKd$a$F$$$J$$>l9g!"%U%)!<%^%C%H$K;HMQ$5$l$k(J String

getPlaceholder

public String getPlaceholder()
$BCM$,%^%9%/$r40A4$KKd$a$F$$$J$$>l9g$K;HMQ$9$k(J String $B$rJV$7$^$9!#(J

$BLa$jCM(J:
$BCM$,%^%9%/$r40A4$KKd$a$F$$$J$$>l9g!"%U%)!<%^%C%H$K;HMQ$5$l$k(J String

setPlaceholderCharacter

public void setPlaceholderCharacter(char placeholder)
$BCM$K$O$J$$J8;z(J ($B$D$^$j%f!<%6$,F~NO$9$kI,MW$N$"$kJ8;z(J) $B$NBe$o$j$K;HMQ$9$kJ8;z$r@_Dj$7$^$9!#%G%U%)%k%HCM$O6uGrJ8;z$G$9!#(J

$B$3$l$O%W%l!<%9%[%k%@J8;zNs$,;XDj$5$l$F$$$J$$$+!"%^%9%/$,40A4$KKd$a$i$l$F$$$J$$>l9g$K$@$1E,MQ2DG=$G$9!#(J

$B%Q%i%a!<%?(J:
placeholder - $BCM$,%^%9%/$r40A4$KKd$a$F$$$J$$>l9g!"%U%)!<%^%C%H$K;HMQ$5$l$kJ8;z(J

getPlaceholderCharacter

public char getPlaceholderCharacter()
$BCM$K$O$J$$J8;z(J ($B$D$^$j%f!<%6$,F~NO$9$kI,MW$N$"$kJ8;z(J) $B$NBe$o$j$K;HMQ$9$kJ8;z$rJV$7$^$9!#(J

$BLa$jCM(J:
$BCM$,%^%9%/$r40A4$KKd$a$F$$$J$$>l9g!"%U%)!<%^%C%H$K;HMQ$5$l$kJ8;z(J

setValueContainsLiteralCharacters

public void setValueContainsLiteralCharacters(boolean containsLiteralChars)
true $B$N>l9g!"La$jCM$H@_DjCM$O$H$b$K%^%9%/$K%j%F%i%kJ8;z$r;}$A$^$9!#(J

$B$?$H$($P!"%^%9%/$,(J '(###) ###-####'$B!"8=:_CM$,(J '(415) 555-1212'$B!"$=$7$F(J valueContainsLiteralCharacters $B$,(J true $B$N>l9g!"(JstringToValue $B$O(J '(415) 555-1212' $B$rJV$7$^$9!#0lJ}!"(JvalueContainsLiteralCharacters $B$,(J false $B$N>l9g!"(JstringToValue $B$O(J '4155551212' $B$rJV$7$^$9!#(J

$B%Q%i%a!<%?(J:
containsLiteralChars - $B%^%9%/$N%j%F%i%kJ8;z$r(J stringToValue $B$KJV$9$+$I$&$+$r<($9$N$K;HMQ$5$l$k(J

getValueContainsLiteralCharacters

public boolean getValueContainsLiteralCharacters()
stringToValue $B$,%^%9%/$N%j%F%i%kJ8;z$rJV$9>l9g!"(Jtrue $B$,JV$5$l$^$9!#(J

$BLa$jCM(J:
$B%^%9%/$N%j%F%i%kJ8;z$,(J stringToValue $B$KJV$5$l$k>l9g$O(J true

stringToValue

public Object stringToValue(String value)
                     throws ParseException
$B%F%-%9%H$r2r@O$7$F!"(JString value $B$NE,@Z$J(J Object $BI=8=$rJV$7$^$9!#CM%/%i%9(J (setValueClass) $B$r;XDj$7$F$"$k>l9g$O$=$N%$%s%9%?%s%9$r:n@.$9$k$?$a!"I,MW$K1~$8$F%j%F%i%kJ8;z$rstringToValue $B$r8F$S=P$7$^$9!#CM$,8=:_$N%^%9%/$K0lCW$7$J$$>l9g!"(JParseException $B$,%9%m!<$5$l$^$9!#(J

$B%*!<%P!<%i%$%I(J:
$B%/%i%9(J DefaultFormatter $BFb$N(J stringToValue
$BLa$jCM(J:
$B%F%-%9%H$N(J Object $BI=8=(J
$BNc30(J:
ParseException - $BJQ49$K%(%i!<$,$"$k>l9g(J

valueToString

public String valueToString(Object value)
                     throws ParseException
$B%^%9%/$K4p$E$$$?(J Object value $B$N(J String $BI=8=$rJV$7$^$9!#(J

$B%*!<%P!<%i%$%I(J:
$B%/%i%9(J DefaultFormatter $BFb$N(J valueToString
$B%Q%i%a!<%?(J:
value - $BJQ49$9$kCM(J
$BLa$jCM(J:
$BCM$N(J String $BI=8=(J
$BNc30(J:
ParseException - $BJQ49$K%(%i!<$,$"$k>l9g(J

install

public void install(JFormattedTextField ftf)
DefaultFormatter $B$rFCDj$N(J JFormattedTextField $B$K%$%s%9%H!<%k$7$^$9!#$3$l$K$h$j(J valueToString $B$,8F$S=P$5$l$F!"8=:_$NCM$,(J JFormattedTextField $B$+$i(J String $B$XJQ49$5$l$^$9!#getActions $B$+$i$N(J Action$B!"(JgetDocumentFilter $B$+$iJV$5$l$?(J DocumentFilter$B!"(JgetNavigationFilter $B$+$iJV$5$l$?(J NavigationFilter $B$,!"(JJFormattedTextField $B$K%$%s%9%H!<%k$5$l$^$9!#(J

$B%5%V%/%i%9$,%j%9%J!<$r(J JFormattedTextField $B$KDI2C%$%s%9%H!<%k$9$k>l9g$O!"DL>o!"$3$l$r%*!<%P!<%i%$%I$9$k$@$1$G$9!#(J

$B8=:_CM$r(J String $B$KJQ49$9$k:]$K(J ParseException $B$,%9%m!<$5$l$k>l9g!"%F%-%9%H$O6u$N(J String $B$K@_Dj$5$l!"(JJFormattedTextField $B$OL58z$J>uBV$H$7$F%^!<%/$5$l$^$9!#(J

$B$3$l$O(J public $B%a%=%C%I$G$9$,!"DL>o$O(J JFormattedTextField $B$N%5%V%/%i%9$KBP$7$F$@$1M-8z$G$9!#CM$,JQ99$5$l$k$+!"FbIt>uBV$,JQ99$5$l$k>l9g!"(JJFormattedTextField $B$K$h$j$3$N%a%=%C%I$,8F$S=P$5$l$^$9!#(J

$B%*!<%P!<%i%$%I(J:
$B%/%i%9(J DefaultFormatter $BFb$N(J install
$B%Q%i%a!<%?(J:
ftf - $B=q<0@_DjMQ$N(J JFormattedTextField$B!#(Jnull $B$b2D(J ($B8=9T$N(J JFormattedTextField $B$N%"%s%$%s%9%H!<%k$r<($9(J)

JavaTM 2
Platform
Std. Ed. v1.4.0

$B%P%0$NJs9p$H5!G=$N%j%/%(%9%H(J
$B$3$l0J30$N(J API $B%j%U%!%l%s%9$*$h$S3+H/ Java 2 SDK SE $B3+H/$B$r;2>H$7$F$/$@$5$$!#(J $B3+H/\:Y$J2r@b!"35G0$N35MW!"MQ8l$NDj5A!"%P%0$N2sHr:v!"(J $B$*$h$S%3!<%I Java$B!"(JJava 2D$B!"$*$h$S(J JDBC $B$OJF9q$J$i$S$K$=$NB>$N9q$K$*$1$kJF9q(J Sun Microsystems, Inc. $B$N>&I8$b$7$/$OEPO?>&I8$G$9!#(J
Copyright 1993-2002 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.