Mask in a JTextField

How I set a mask (for example for a date) in a JTextField??? I think that I can make it using a Document, but how???
Thanks in advance!!!

First sorry for one mistake: TextDocument is not a standard class, the right one is PlainDocument.
Here is an example:
public class TextDocument extends PlainDocument{
    protected int characterLimit = 10;
     private int firstDayDigit = 0;
     public TextDocument() {
          this(10);
     public TextDocument(int limit) {
          super();
          characterLimit = limit;
      * Process the input from the user and check for the
      * right numbers.
     public void insertString(int offset, String str, AttributeSet attrib) throws BadLocationException {
          if(offset == 0 && !str.equals("00.00.0000")){
               try{
                    firstDayDigit = Integer.parseInt(str);
               }catch(NumberFormatException nfe){
                    Toolkit.getDefaultToolkit().beep();
                    return;
          if(!str.equals("00.00.0000")){
               try{
                    int digit = Integer.parseInt(str);
               }catch(NumberFormatException nfe){
                    str = "0";
          if(str.length() == 1) {
               switch(offset){
                    case 0:
                         //check for the correct day
                         if(Integer.parseInt(str) > 3){
                              str = "0";
                         removeIt(offset, str, attrib);
                         break;
                    case 1:
                         if(firstDayDigit == 3){
                              if(Integer.parseInt(str) > 1){
                                   str = "0";
                         removeIt(offset, str, attrib);
                         break;
                    case 3:
                         //check for the correct month
                         if(Integer.parseInt(str) > 1){
                              str = "0";
                         removeIt(offset, str, attrib);
                         break;
                    case 6:
                         //check for the correct year
                         if(Integer.parseInt(str) != 2){
                              str = "2";
                         removeIt(offset, str, attrib);
                         break;
                    case 4:
                    case 7:
                    case 8:
                    case 9:
                         removeIt(offset, str, attrib);
                         break;
                    case 2:
                        // user did not type in a '-'
                        if(!str.equals(".")) {
                              // remove the '.' if there is one
                              try{
                                   remove(offset, 1);
                              }catch(BadLocationException ble){
                                   // don't throw back to calling method
                              // insert another '.'
                              super.insertString(offset, ".", attrib);
                              // remove the next character in the field
                              try {
                                   remove(offset + 1, 1);
                              } catch(BadLocationException ble) {
                                   // don't throw back to calling method
                              if(Integer.parseInt(str) > 1){
                                   str = "0";
                              // insert the new character in it's place
                              super.insertString(offset + 1, str, attrib);
                         } else {
                              // user did type in a '.', remove the old on
                              try {
                                   remove(offset, 1);
                              } catch(BadLocationException ble){
                                   // don't throw back to calling method
                              // and insert a new one
                              super.insertString(offset, str, attrib);
                         break;
                    case 5:
                        // user did not type in a '.'
                        if(!str.equals(".")) {
                              // remove the '.' if there is one
                              try{
                                   remove(offset, 1);
                              }catch(BadLocationException ble){
                                   // don't throw back to calling method
                              // insert another '.'
                              super.insertString(offset, ".", attrib);
                              // remove the next character in the field
                              try {
                                   remove(offset + 1, 1);
                              } catch(BadLocationException ble) {
                                   // don't throw back to calling method
                              if(Integer.parseInt(str) != 2){
                                   str = "2";
                              // insert the new character in it's place
                              super.insertString(offset + 1, str, attrib);
                         } else {
                              // user did type in a '.', remove the old on
                              try {
                                   remove(offset, 1);
                              } catch(BadLocationException ble){
                                   // don't throw back to calling method
                              // and insert a new one
                              super.insertString(offset, str, attrib);
                         break;
                    default:
                         throw new BadLocationException("Limit of " + characterLimit + " characters.", offset);
          } else {
               for(int i = offset; i < offset + str.length(); i++) {
                    insertString(i, ""+ str.charAt(i), attrib);
     protected void removeIt(int offset, String str, AttributeSet attrib) throws BadLocationException{
          try {
               remove(offset, 1);
          }catch(BadLocationException ble) {
          super.insertString(offset, str, attrib);
}

Similar Messages

  • How to implement  a mask in a JtextField??? Is it  possible???

    I wish to have a masked edit box in Java ( a control present in VB). It is similar to a JTextField. In the control, if I specify a mask for data entry such as 99/99/9999 the box will appear on the form with dashes as --/--/----, and it will allow data entry only on those dashes and only numbers. Similarily for characters you specify "#".
    Anyone has an idea of java controls that can be used in Java for this purpose???
    I already know how to validate a date��.for that I used SimpleDateFormat�..but I would like that in the jtextfield appears something like --/--/---- because my user will introduce the date.
    Thanks in advance,
    Mary

    Yes it is possible.....i found how reach it...
    date = new JFormattedTextField (new MaskFormatter("##/##/####")) ;
    Thanks any way,
    Mary

  • To fix the length of a textfield for user to enter date

    hi,
    i need to display a textfield for user to enter the date in the format MM/DD/YY.With the slash in between present and fixed and the possibility of entering only 2 digit figures for the month,day n' year.I am using JTextField .how can i acheive that pls help.

    You must design you own document where you will manage the text that will be entered/displayed in your textfield
    here's a sample of the code I use to do this:
    import javax.swing.JTextField;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.event.*;
    public class MaskedTextField extends JTextField
    private String initStr;
    public MaskedTextField (String mask, String initStr)
    super();
    setDocument(new MaskedDocument(initStr, mask, this));
    setText(initStr);
    this.initStr = initStr;
    this.addMouseListener(new java.awt.event.MouseAdapter()
    public void mouseClicked(MouseEvent m)
    this_mouseClicked(m);
    private void this_mouseClicked(MouseEvent m)
    if (getText().equals(initStr)) setCaretPosition(0);
    class MaskedDocument extends PlainDocument
    String mask;
    String initStr;
    JTextField tf;
    public MaskedDocument(String initStr, String mask,
    MaskedTextField container)
    this.mask = mask;
    this.initStr = initStr;
    tf = container;
    void replace(int offset, char ch, AttributeSet a)
    throws BadLocationException
    super.remove(offset,1);
    if (capitalised) super.insertString(offset,
    String.valueOf(ch).toUpperCase(),a);
    else super.insertString(offset, "" + ch, a);
    public void remove(int offs, int len) throws BadLocationException
    if (len==0)
    return;
    // Remove current contents
    super.remove(offs, len);
    // Replace the removed part by init string
    super.insertString(offs,initStr.substring(offs,offs+len),
    getAttributeContext().getEmptySet());
    tf.setCaretPosition(offs);
    public void insertString(int offset, String str, AttributeSet a)
    throws BadLocationException
    if ((offset==0) && str.equals(initStr))
    // Initialisation of text field
    super.insertString(offset,str,a);
    return;
    if (str.length()==0)
    super.insertString(offset,str,a);
    return;
    for (int i=0;i<str.length();i++)
    while ((offset+i) < mask.length())
    if (mask.charAt(offset+i)=='-')
    // Skip fixed parts
    offset++;
    else
    // Check if character is allowed according to mask
    if (str.charAt(i) != this.initStr.charAt(i))
    switch (mask.charAt(offset+i))
    case 'D': // Only digitis allowed
    if (!Character.isDigit(str.charAt(i)))
    return;
    break;
    case 'C': // Only alphabetic characters allowed
    if (!Character.isLetter(str.charAt(i)))
    return;
    break;
    case 'A': // Only letters or digits characters allowed
    if (!Character.isLetterOrDigit(str.charAt(i)))
    return;
    break;
    replace(offset+i, str.charAt(i),a);
    break;
    else
    i++;
    offset--;
    // Skip over "fixed" characters
    offset += str.length();
    while ((offset<mask.length()) && (mask.charAt(offset)=='-'))
    offset++;
    if (offset<mask.length())
    tf.setCaretPosition(offset);
    if (offset == mask.length()) tf.setCaretPosition(offset);
    Enjoy
    Bernie

  • Jtexfield converted to jtextfield_date ?.

    hi!
    how can i put a sort of mask to my jtextfield sothat it looks like "dd/mm/yyyy" so that i don't have to control date typed in it !
    please help

    Its available in JDK1.4.
    Here is a class that works in JDK1.3 that you might be able to use:
    http://www.discoverteenergy.com/files/TextGroup.java
    Just download and run the class to get an idea of what it can do.

  • Formatting a textfield

    I would like to format a text field to accept a phone number eg (***) *** - ****
    How do I create this mask?
    I have seen JMaskField mentioned but I can not find any examples. Could anyone provide an example of how to use JMaskField or have you got any other suggestions?
    Thank you

    hi soughtred,
    Try the following code. I hope this is what you want.
    import java.io.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.event.*;
    class MaskedTextField extends JTextField {
    public MaskedTextField (String mask, String initStr) {
    super();
    setDocument(new MaskedDocument(initStr, mask, this));
    setText(initStr);
    setColumns(mask.length()+1);
    class MaskedDocument extends PlainDocument {
    String mask;
    String initStr;
    JTextField tf;
    public MaskedDocument(String initStr, String mask, JTextField container) {
    this.mask = mask;
    this.initStr = initStr;
    tf = container;
    void replace(int offset, char ch, AttributeSet a)
    throws BadLocationException {
    super.remove(offset,1);
    super.insertString(offset,""+ch,a);
    public void remove(int offs, int len) throws BadLocationException {
    System.out.println("R:"+len+","+offs);
    if (len==0)
    return;
    // Remove current contents
    super.remove(offs, len);
    // Replace the removed part by init string
    super.insertString(offs,initStr.substring(offs,offs+len),
    getAttributeContext().getEmptySet());
    tf.setCaretPosition(offs);
    public void insertString(int offset, String str, AttributeSet a)
    throws BadLocationException {
    if ((offset==0) && str.equals(initStr)) {
    // Initialisation of text field
    super.insertString(offset,str,a);
    return;
    if (str.length()==0) {
    super.insertString(offset,str,a);
    return;
    for (int i=0;i<str.length();i++) {
    while ((offset+i) < mask.length()) {
    if (mask.charAt(offset+i)=='-')
    // Skip fixed parts
    offset++;
    else {
    // Check if character is allowed according to mask
    switch (mask.charAt(offset+i)) {
    case 'D': // Only digitis allowed
    if (!Character.isDigit(str.charAt(i)))
    return;
    break;
    case 'C': // Only alphabetic characters allowed
    if (!Character.isLetter(str.charAt(i)))
    return;
    break;
    case 'A': // Only letters or digits characters allowed
    if (!Character.isLetterOrDigit(str.charAt(i)))
    return;
    break;
    replace(offset+i, str.charAt(i),a);
    break;
    // Skip over "fixed" characters
    offset += str.length();
    while ((offset<mask.length()) && (mask.charAt(offset)=='- ')) {
    offset++;
    if (offset<mask.length())
    tf.setCaretPosition(offset);
    public class test {
    public static void main(String[] args) {
    final JFrame f = new JFrame("Textfield demo");
    f.setDefaultCloseOperation(f.DISPOSE_ON_CLOSE);
    f.addWindowListener(new WindowAdapter() {
    public void windowClosed(WindowEvent e) {
    System.exit(0);
    f.setSize(250,70);
    MaskedTextField tf=new MaskedTextField("DD-D-D-DDD-DDDD","..-
    tf.setFont(new Font("Monospaced", Font.BOLD, 14));
    JPanel panel = new JPanel();
    panel.add(tf);
    f.getContentPane().add(panel);
    f.setVisible(true);

  • JTextField - Show date format mask while inputing

    I have searched through the forums and I have not found an instance of someone try to show the format mask while a user inputs chars:
    ex: **/**/**** <-- Initialized
    1*/**/**** <-- After first integer
    10/3*/**** <-- After third integer
    I would also like the keep the caret position at the last integer and not always at the end of the input.
    Also if a user enters a "t"||"T" that it will automatically enter today's date.
    Is there a quick way? I have tried to use a DefaultStyledDocument but have not had success.
    Thanks

    here's a starter
    (needs to handle backspace, delete and probably a few other keys)
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.text.*;
    class Testing extends JFrame
      JTextField tf = new JTextField(new MyDoc(),"**/**/**",10);
      public Testing()
        setLocation(400,300);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JPanel jp = new JPanel();
        jp.add(tf);
        getContentPane().add(jp);
        pack();
      class MyDoc extends PlainDocument
        public void insertString(int offs, String str, AttributeSet a) throws BadLocationException
          if(str.equals("**/**/**") == false && (offs == 2 || offs == 5 ||
             str.length() > 1 || offs > 7 || "0123456789".indexOf(str) < 0))
            java.awt.Toolkit.getDefaultToolkit().beep();
            return;
          StringBuffer newText = new StringBuffer(getText(0,getLength()));
          if(newText.length() > 0)
            newText.setCharAt(offs,str.toCharArray()[0]);
            remove(0,getLength());
            super.insertString(0,newText.toString(),a);
            if(offs == 1 || offs == 4) tf.setCaretPosition(offs+2);
            else tf.setCaretPosition(offs+1);
          else super.insertString(offs,str,a);
      public static void main(String[] args){new Testing().setVisible(true);}
    }

  • JtextField , mask input and setText() ...

    ... I use two JTextFields on wich i put a LimitedStyle Document in order to only allow the user
    to input dates in a specific format. Unfortunally, this input mask seems to block the setText()
    function of the JTextField. I can't set the Field to the current DateSytem regarding the date format
    i use (the date is in the right format input). Does someone know how to bypass this problem ?
    If needed i can post the code source of the Document.
    Thanks in advance,
    Marc.

    jTextField.getDocument().setText()
    dosen't work because there is no setText(0 method on document.
    instead i am doing this
    Document docm = new ShowDocument(userInput);
    ShowDocument is a class which overrides insertString() method
    import javax.swing.text.PlainDocument;
    import javax.swing.text.AttributeSet;
    import javax.swing.text.BadLocationException;
    public class ShowDocument extends PlainDocument
    String st=null;
    public ShowDocument(String s)
    this.st = s;
    public void insertString(int offs, String str, AttributeSet a) throws BadLocationException
    super.insertString(offs, st,a);
    return;
    this works fine.

  • Date format in a JTextField

    I have created 2 jtextfields to enter a start and stop date for printing a report within the date range selected. How do format the jtextfields to insure they are properly date formatted i.e. MM/dd/yyyy
    Thanks, William

    If you create an input binding of Formatted Text Field, you can specify the format mask by right-clicking the binding and clicking "Edit" from the structure pane. Then select "Format" and set whatever date format you need. This is true in 10.1.2, so it might not be available depending on what version you are using.

  • Problem with a mask in a JFormattedTextField

    I am tring to create a text box with a mask.
    This object text box is declared like a class var.
    I have another object, a mask object that is also declared as a class var
    but I cant create this mask. The errors are commented,
    if you erase the comments and create the class you are going to see the error.
    javac ContraBase.java
    java ContraBase
    Estoy tratando de crear un campo de texto con mascara.
    este objeto texto esta definico como variable de clase
    tengo definida una mascara tambien como variable de clase
    Pero no me deja crear la mascara. Los errores estan comentados,
    si quita los comentados y crea el class vera el problema.
    javac ContraBase.java
    java ContraBase
    import java.sql.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.JFormattedTextField;
    class ContraBase extends JPanel
         //MaskFormatter mascara1 = new MaskFormatter("########"); //aca se produce un error
         //JFormattedTextField PRECIOA = new JFormattedTextField (mascara1); //la idea es definir aca la mascara
         JFormattedTextField PRECIOA = new JFormattedTextField ("########");
         public ContraBase()
              //TEXTBOX
              PRECIOA.setToolTipText("PRECIOA");
              add(PRECIOA);
         static public void main (String[] args)
              System.out.println("Iniciando programa.");
              try
                   JFrame VentanaPrincipal = new JFrame("Practicas con Java, trabaja con Base");
                   VentanaPrincipal .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   VentanaPrincipal .getContentPane().add(new ContraBase(), BorderLayout.CENTER);
                   VentanaPrincipal .setSize(350,500);
                   VentanaPrincipal .setVisible(true);
              catch(Exception e)
                   System.out.println("****INGRESA A EXCEPTION main****");
                   System.out.println(e.toString());
                   System.out.println("****SALE DE EXCEPTION main****");
                   return;
              System.out.println("Creacion Finalizada.");
    }

    Sounds like that field is editable. The renderer renders the display when a field is not
    being edited, a TableCellEditor is in charge when the field is edited, and the default
    editor is just a JTextField.
    : jay

  • How can i format a JTextField to a Date format?

    How can i do to format a JTextField to a date format, may be with a mask, wich is the way to do this?

    What exactly do u mean by formatting a JTextField to date?
    Is it like - what ever the user enters should be stored as date?
    Could you explain in more detail what exactly you want the function to do?
    Best,
    Radha

  • Custom event mask

    I have defined a custom new event:
    private class MyEvent extends AWTEvent {
              public MyEvent(Object source, String msg) {
                   super(source, 2000);
                   this.msg = msg;               
              public String getMsg() {
                   return msg;
              private String msg;
         }as you can see the id is 2000 which is bigger than AWTEvent.RESERVED_ID_MAX
    Now in the constructor of my JFrame: CustomEventListener
    I've added the following code:
    Toolkit.getDefaultToolkit().addAWTEventListener(
                        this, 2000);I want to be able that when I call "disptachEvent" with my event the method
    "eventDispatched" will be called in my code, but I don't understand
    what value should I set the mask in the addAWTEventListener method.
    And in general I don't understand how the correlation between masks
    to events work, is there some formula that if the event's id is x then
    the mask should be some multiple of x or something like that?
    Here is my full application:
    import java.awt.AWTEvent;
    import java.awt.EventQueue;
    import java.awt.FlowLayout;
    import java.awt.Toolkit;
    import java.awt.event.AWTEventListener;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    public class CustomEventListener extends JFrame implements
    AWTEventListener, ActionListener {
          * @param args
         public static void main(String[] args) {
              JFrame myFrame = new CustomEventListener();
              myFrame.setVisible(true);
              myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public CustomEventListener() {
              setLayout(new FlowLayout());
              btn = new JButton("Click me");
              add(btn);
              textField = new JTextField(10);
              add(textField);
              pack();
                    // what value should I use for the mask
              Toolkit.getDefaultToolkit().addAWTEventListener(
                        this, 2000);
         public void eventDispatched(AWTEvent event) {
              System.out.println("boga boga");                    
         public void actionPerformed(ActionEvent e) {
              if (e.getSource() == btn) {
                   dispatchEvent(new MyEvent(this, "the button has been clicked"));
         private JButton btn;
         private JTextField textField;
         private class MyEvent extends AWTEvent {
              public MyEvent(Object source, String msg) {
                   super(source, 2000);
                   this.msg = msg;               
              public String getMsg() {
                   return msg;
              private String msg;
    }I know that I can use listeners in this example, but I don't
    want to use a listener for the dispatching of my event for reasons
    which are a bit hard to explain.
    Thanks in advance

    Hi,
    First say ur Jdev Version................
    U can validate in ADF in both Model and ViewLayer itself... In ViewLayer u can have Validators as regular Expression Validators
    Have a look into these first....
    http://jdevadf.oracle.com/adf-richclient-demo/docs/tagdoc/af_validateRegExp.html
    http://download.oracle.com/docs/cd/E14571_01/web.1111/b31973/af_validate.htm#ADFUI827
    Regards,
    Suganth.G

  • Help:How to make static text in JTextField??

    How to make a text to be displayed initially on a JTextField, yet we can not change the text (so the text
    is static)?
    The other question:
    How to make an input mask so that a JTextField
    has input pattern of XXX.XXX.XXX.XXX
    (which is the mask of IP Address) ??
    What I know that limiting input in JTextField can be done
    by extending PlainDocument....what about the cases above??
    Please reply if you know.
    Thanks a lot,
    Ted.

    For the first question, just call setEditable(false).

  • How to mask and format an input field at the same time?

    Dear Experts,
    I need to have an input field, which has the following behavior:
    1. The input field accepts only number, i.e. characters other than number are ignored (not displayed on the text field).
    2. The number is automatically formatted to ###,###,### as the user enter the number.
    Example as the user enter 1-2-3-4-5-6-7, the sequence of number displayed in the text field is:
    1
    12
    123
    1,234
    12,345
    123,456
    1,234,567
    I have done the following:
    import java.awt.*;
    import javax.swing.*;
    import java.text.*;
    import javax.swing.text.*;
    class FormattedTFDemo {
         NumberFormat cf;
         JLabel jlab;
         JFormattedTextField jftfSalary;
         JFormattedTextField jftfEmpID;
         JButton jbtnShow;
         public FormattedTFDemo() {
              JFrame jfrm = new JFrame("JFormattedTextField");
              jfrm.getContentPane().setLayout(new FlowLayout());
              jfrm.setSize(240, 270);
              jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              try {
                   MaskFormatter mf = new MaskFormatter("###,###,###");
                   jftfEmpID = new JFormattedTextField(mf);
              } catch (ParseException exc){
                   System.out.println("Invalid Format");
                   return;
              jftfEmpID.setColumns(15);
              cf = new DecimalFormat("###,###,###");
              jftfSalary = new JFormattedTextField(cf);
              jftfSalary.setColumns(15);
              jftfSalary.setValue(new Integer(7000));
              jfrm.getContentPane().add(new JLabel("First field"));
              jfrm.getContentPane().add(jftfEmpID);
              jfrm.getContentPane().add(new JLabel("Second field"));
              jfrm.getContentPane().add(jftfSalary);
              jfrm.setVisible(true);
         public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        new FormattedTFDemo();
    }The "First field" adopts no. 1 behavior, i.e. it does not allow any character other than numbers, but the "," are always displayed and the number displayed as I enter 1-2-3-4-5-6-7 are:
    1 , ,
    12 , ,
    123, ,
    123,4 ,
    123,45 ,
    123,456,
    123,456,7
    which is not according to behavior no. 2
    The "Second field" displayed 1,234,567 only after the focus left the text field and not while typing. Moreover, characters other than number can still be displayed and only rejected after the focus left the text field.
    I need a guide of what text field and what filter / format / mask I should use. Am I correct to use JFormattedTextField? Is the only way to accomplish this by using JTextField and create my own PlainDocument for the textfield, where
    I rebuild the displayed output after each character is entered?
    Thanks for any advice,
    Patrick

    So exactly what do you want the user to put in? and what do you want to see?
    I need to have an input field, which has the following behavior:
    1. The input field accepts only number, i.e. characters other than number are ignored (not displayed on the text field).
    2. The number is automatically formatted to ###,###,### as the user enter the number.
    Example as the user enter 1-2-3-4-5-6-7, the sequence of number displayed in the text field is:
    1
    12
    123
    1,234
    12,345
    123,456
    1,234,567The user should type only numbers and when he types other than numbers, the field ignore it.
    What I want to see, as the user, for example, types 1-2-3-4-5-t-6-7 is:
    1
    12
    123
    1,234
    12,345
    <beep / ignore> (because t is invalid)
    123,456
    1,234,567
    Thus, I need a guide of what swing components should I use to accomplish this task. If you can give me the code, that will be perfect.
    Hope you can advise me,
    Patrick

  • My own JTextField

    In a fitness database that I am developing I am hoping to have a JTextField that the user can enter the duration of their workout. I want the format to be preset to 00:00, and the user would just enter in number that would fill in accordingly.
    Should I write my own class that extends JTextField or is there a better way to do this?
    Thanks in advance for any input!

    Thank you for your timely response. Despite my username disclaimer, I feel foolish for not having found that myself!
    Anyway, as expected, I have run into some problems now with the JFormattedTextField. Here is the relevant code:
    class WorkoutDefPanel extends JPanel
        MaskFormatter mf = new MaskFormatter();
        JFormattedTextField woDur = new JFormattedTextField(mf);
        public WorkoutDefPanel()
         woDur.setLocation((int)(frameW * 0.28),(int)(frameH * 0.25));
         woDur.setSize((int)(frameW * 0.06),(int)(frameH * 0.05));
         //duration text field's input mask
         try{
             mf.setMask("#:##");
             mf.setPlaceholderCharacter('0');
             mf.setValueContainsLiteralCharacters(false);
         }catch(ParseException ex){}
         add(woDur);
        //this is called from my JFrame class when the user selects a "LOG" button
        public void log()
         int t = 0;
         try{
             mf.commitEdit();
             t = Integer.parseInt(mf.valueToString(woDur.getValue()));
         }catch(ParseException ex){}
         int d = ((t/100)*60)+(t % 100);
         Workout nw = new Workout(d);
    }I am getting a NumberFormatException at t = Integer.parseInt(mf.valueToString(woDur.getValue()));Also, strangely, the value which throws the exception is 0:00 even after it has been edited. The value only changes to the edited value once enter is pressed, but I still get the runtime exception.
    Any thoughts?
    Appreciated,
    Jeremy

  • Reserved characters prepended by the masking delimiter in EDIFACT

    Hi All
    I have a X2E mapping where I may get the reserved characters like +:'? in the input xml.
    What happens is that BICMD prepends the reserved characters by the default masking character ?.
    For example my input is       apple+ball:bat's
    then my BICMD output is      apple?+ball?:bats?'s
    what i want is that input should remain unchanged in the output of the BICMD.
    Also i dont want the UNA segment to appear in the BICMD output.
    Does any one know what properties i need to change in the BIC MD in order to achieve the desired output?

    JTextField has PlainDocument as Model. Write your own PlainDocument and set this as model to JTextField.

Maybe you are looking for