Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-07-2009, 11:26 AM
Member
 
Join Date: Feb 2009
Posts: 9
Rep Power: 0
Ralphw is on a distinguished road
Default JFormattedTextField + SimpleDateFormat
Hi *

i am creating a Dateformat with "YYYY" a set the Dateformatter into the JFormattedTextField.

I expected a text field where i can only edit 4 digits.
But i can put in even more digits.

Whats wrong ?

HTML Code:
import java.awt.BorderLayout;
import java.text.SimpleDateFormat;
 
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.text.DateFormatter;
 
public class JFormattedTF extends JFrame {
 
  public JFormattedTF() {
    JPanel panel = new JPanel();
    JLabel label = new JLabel("Year :");
    SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy");
    DateFormatter df = new DateFormatter(yearFormat);
    JFormattedTextField tf = new JFormattedTextField(df);
    ((DateFormatter)tf.getFormatter()).setAllowsInvalid(false);
    tf.setColumns(4);
    panel.add(label);
    panel.add(tf);
    getContentPane().add(panel, BorderLayout.SOUTH);
    pack();
  }
 
  public static void main(String[] args) {
    JFormattedTF tfe = new JFormattedTF();
    tfe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    tfe.setVisible(true);
  }
}  
     
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 07-07-2009, 11:53 AM
RamyaSivakanth's Avatar
Senior Member
 
Join Date: Apr 2009
Location: Chennai
Posts: 533
Rep Power: 1
RamyaSivakanth is on a distinguished road
Default
Hi,
I think no methods are avilable in the api.You have to check like this below

if(tf.getText().length() > 4 )

-Regards
Ramya
__________________
Ramya
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use SimpleDateFormat in J2ME Applications thirupathik CDC and Personal Profile 6 09-03-2009 12:47 PM
Locale with SimpleDateFormat swati.jyoti New To Java 4 07-02-2009 03:34 PM
Problems with JFormattedTextField Gatts79 New To Java 0 10-03-2008 05:59 PM
Using SimpleDateFormat Java Tip Java Tips 1 07-18-2008 09:33 AM
JFormattedTextField Issue teracomp AWT / Swing 1 01-21-2008 07:55 PM


All times are GMT +2. The time now is 04:33 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org