代码之家  ›  专栏  ›  技术社区  ›  Jeff Storey

带MaskFormatter的JFormatedTextField

  •  12
  • Jeff Storey  · 技术社区  · 14 年前

    JFormattedTextField MaskFormatter 但显示占位符字符。有什么方法可以使用 掩码器 在上面 格式文本字段 当文本字段已经使用 SimpleDateFormat

    3 回复  |  直到 11 年前
        1
  •  28
  •   I82Much    14 年前
    public class maskformatterest{
    private static final dateformat df=new simpledateformat(“yyyy/mm/dd”);
    
    
    公共静态void main(string[]args){
    frame.setDefaultCloseOperation(jframe.exit在关闭时退出);
    jpanel panel=new jpanel();
    
    jFormattedTextField tf=新建jFormattedTextField(df);
    添加(TF);
    maskFormatter dateMask=新的maskFormatter(“35;//”);
    }
    
    框架。添加(面板);
    帧();
    frame.setVisible(真);
    }
    
    

    alt text

    除非我误解了这个问题。

        2
  •  2
  •   Community CDub    8 年前

    或者,考虑 InputVerifier ,如中建议的 InputVerificationDemo 这个更详细 example .

        3
  •  -2
  •   Mohamed Saligh    14 年前
    JFormattedTextField tft3 = 
        new JFormattedTextField(new SimpleDateFormat("yyyy-MM-dd"));
        tft3.setValue(new Date());
    
        Date date = (Date) tft3.getValue();