Masked JTextFields

Discussion in 'Java' started by Ike, Jun 7, 2006.

  1. Ike

    Ike Guest

    Is there a way, for a given JTextField, to mask it? In other words, is there
    a way by which to make it so that the data must be put in as HH:mm:ss say?
    Such that the user would see (if there were nothing in the field):
    HH:mm:ss

    With a Document then that only allowed numeric entried in all but the 2nd
    and 5th character positions (where no matter what was typed, you;d only see
    ":". I know how to do a Document that shows this, but how can you actually
    make it "masked" so it appears like a masked field? Thanks, Ike
    Ike, Jun 7, 2006
    #1
    1. Advertising

  2. Ike

    Paul Hamaker Guest

    import javax.swing.text.MaskFormatter;

    MaskFormatter mf = new MaskFormatter( "##:##:##" );
    tf = new JFormattedTextField ( mf ) ;
    --------------------
    Paul Hamaker, SEMM, teaching ICT since 1987
    http://javalessons.com
    Paul Hamaker, Jun 7, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. |{evin
    Replies:
    7
    Views:
    554
    |{evin
    Nov 18, 2003
  2. =?Utf-8?B?bWV0cmlkZXZraw==?=

    Masked Edit Control

    =?Utf-8?B?bWV0cmlkZXZraw==?=, Dec 3, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    4,112
    Steve C. Orr [MVP, MCSD]
    Dec 3, 2004
  3. =?Utf-8?B?ZGF2aWQ=?=
    Replies:
    1
    Views:
    3,737
    Ken Cox [Microsoft MVP]
    Apr 19, 2005
  4. George
    Replies:
    3
    Views:
    3,257
    Roedy Green
    Oct 15, 2007
  5. albert kao
    Replies:
    6
    Views:
    1,352
    Knute Johnson
    Apr 26, 2011
Loading...

Share This Page