Search code examples
javaswingdatejtextfieldsimpledateformat

Only take specific information from text field


I was wondering how you can take just specific characters from a JTextField. For example if a JTextField has the date 20/12/2012 then how do you read only the "12" form the Field.

So is it possible and if so how or would it be easier to use multiple JTextFields?


Solution

  • One approach would be read full text, but split string based on "/" and take 0 index value in resulting array.

    (or)

    Parse String using SimpleDateFormatter and get Month from Date (assuming entered string will be always date)

    If none of above works, then it would be easier to use multiple text fields