How do your restrict valid input into a JFormattedTextField

Hi
I'm interested in setting up a text box that only accepts a one or two digit integer value - so it would stop the user from inputting any character that wasnt a digit, and stop the user from inputting more than two digits - this must be something that is commonly done.
Thanks, Dave

Well, I'm confused by your question. JDK1.4 has a class called JFormattedTextField. I don't have JDK1.4 so I can't tell you how to use it, but from other posts I've seen on the forum I think it is something like:
JFormattedTextField field = new JFormattedTextField( "##" );
If you don't use JDK1.4 then you can create a custom Documents which will do what you need. The Swing tutorial on "General Rules for Using Text Components" will help:
http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html
http://java.sun.com/docs/books/tutorial/uiswing/components/textfield.html#validation
The first link shows how to limit a document to 'x' character. The second on how to check for numeric values.

Similar Messages

  • How can I have multiple inputs into the selector terminal of a case structure

    Hi everyone
    I have a question on how to wire multiple inputs in to the selector terminal of a case structure. 
    Currently, I have three switches, each switch determines different case. So if I switch the switch 1 is on, the numeric indicator will show 1. If the switch 2 is on, the numeric indicator will show 2, so on and so forth. However, the selector terminal will not allow me to wire multiply inputs into the case structure, I tried Bundle by Name, Bundle and Array to Cluster, but they did not work. I set the case structure with 3 cases, they are 1, 2 and 3.
    Could someone help me please. I have attach an image and the VI of the work I did so far.
    I have another question, is there a function which can toggle other switches to off when there is a switch has been toggled on.
    Thank you very much
    Tommy
    Attachments:
    Trial - Case Structure.vi ‏7 KB

    Tommy, attached find a cheeseball way of doing this that has given me a LOT of mileage over the years.  IT lends itself nicely to a couple of really good practices that NI recommend, but I have given you the bare-bones to "see under the hood".  
    The recommended practices:
    1. You can make this a nice tight sub-vi where you can put it into a core library of routines that you'll use over the years, even extending the logic to look only for changes, etc.
    2.  If you are thinking about Front Panel design considerations, you'll want to use arrays of controls where possible, as that's a nice neat way of containerizing your switch for both the FP and Block Diagram.
    Have fun.  I have TONS of these types of things, so feel free to PM me if you have any other needs.
    Wes
    Wes Ramm, Cyth UK
    CLD, CPLI
    Attachments:
    Boolean Switch Logic.vi ‏11 KB

  • How to bring my valid iMovie into Soundtrack Pro as a multitrack?

    Hello kind people. My most hummed song right now is "I can't get started with you." To my shame, I am unable to bring my valid iMovie into Soundtrack Pro as a multitrack. I have brought the audio alone, but that leaves me grabbing at air. There must be a simple way. Who will tell me how?
    PBG4 17   Mac OS X (10.4.6)  

    Try exporting a Quicktime movie from iMovie, then drag the quicktime movie onto the video track (or drop it into the video window) in Soundtrack Pro.

  • How to read only valid input

    Hi!
    I need to validate data. Users can enter either binary, hex, oct or decimal numbers but the program should check for two things length of the number and each digit that constitute the number. For example
    the user could mix other chars in a binary number eg. 100g110 or they could do something like 4583y90 for decimal number. i need to check the strings like the one which would contain 100g110, and print error message and ask for another input, now when the user enters a new input i will have to check both of the things again the length and the valid character for that number type...please help...thanks in advance
    speedOfLife

    I think i got it. Or at least it shouldn't be wildly different than how I think the error should be checked. But, I wish there were an easier and more efficient way to do the same.
    please take a look at how i am checking numbers.
    I have two functions, they check string length and then check each and every digit to see if they are either (0 or 1) or not. These two functions are being called from the main and after the boolean results are returned from the functions...i m using a while loop to doulbe check if both of the boolean are true...if not then i m throwing error messages...so i mean to say...it works and i m happy but i hate to admit that it took over 6 hours of total time just to do a tiny thing...i wish there was something else i could do...because now i have to do the same kind of coding for hex, decima and octal...please have a look how i did for binary
    static boolean getRightSize(String str)throws IOException{
              boolean ok1, ok2;
              ok1 = false;
              ok2 = false;
              long num;
               if (str.length()<=31 )
                ok1 = true;
              else
                ok1 = false;
         return ok1;
       }//end getRightSize()             
         static boolean getValidDigit(String str){
              boolean ok;
              int length = str.length() - 1;
              int l;
              ok = false;
               for ( l = 0; l <= length;  l++ ){
                     if( str.charAt(l) == 48 )
                      ok = true;
                    else if(str.charAt(l) == 49 )
                      ok = true;                 
                    else
                      ok = false;
               return ok;
         }//end getValidDigit()the main is four times conbined the codes above...which looks messy...
    anyway...thanks a lot.
    it is fun for me being a rookie...
    later

  • How to cast a String input into Date variable?

    I am using JOptionPane.showInputDialog to ask user for a date input. This will be read in as a String. I need to pass it to a variable call date. And when I print date using JOptionPane, it should be shown as whatever the user keyed in in this format: 25/2/09. How do I do it?

    By the way, that's not casting. Casting is when you have a variable whose type is at a particular level of detail, and you assign it a different level of detail -- say, casting an int to a long, or a List to an ArrayList.
    What you want to do is convert one type to a completely different one. In particular, you're going to do that by using SimpleDateFormat to parse the String -- that is, SimpleDateFormat will read the string, pick out the individual parts that express the date, and create a Date object that corresponds to it.

  • Restrict the input string length

    Hi, how do I restrict the input string length in a JTextField. Suppose if I want my text field to accept only 4 characters, the fifth character I try to enter shouldn't be accepted in the field.
    Thanks,
    Kalyan.

    This is for 6 characters limit
    //create a JTextField that is six characters long
    JTextField textField = new JTextField(new FixedNumericDocument(5,true),"", 6);
    Here boolean true means only numeric. set to false to take in alphanumeric.
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    public class FixedNumericDocument extends PlainDocument {
    private int maxLength = 9999;
    private boolean numericOnly;
    public FixedNumericDocument(int maxLength, boolean numericOnly) {
    super();
    this.maxLength = maxLength;
    this.numericOnly = numericOnly;
    //this is where we'll control all input to our document.
    //If the text that is being entered passes our criteria, then we'll just call
    //super.insertString(...)
    public void insertString(int offset, String str, AttributeSet attr) throws BadLocationException {
    if (getLength() + str.length() > maxLength) {
    return;
    else {
    try {
    if (numericOnly) {
    Integer.parseInt(str);
    //if we get here then str contains only numbers
    //so that it can be inserted
    super.insertString(offset, str, attr);
    catch(NumberFormatException exp) {
    return;
    return;

  • I am trying to set up my apple tv on a sony KDL - 40xbr4. The remote is a sony RM-V302. I plugged it into the HDMI IN on the side of the TV but cannot find out how to get to that input. I am at a winter rental property and brought my Apple TV with me.

    I am trying to set up my apple tv on a sony KDL - 40xbr4. The remote is a sony RM-V302. I plugged it into the HDMI IN on the side of the TV but cannot find out how to get to that input. I am at a winter rental property and brought my Apple TV with me. I did check internet for solutions. The instructions I found said to use a "home button" on the remote.  There isn't one. I sure would appreciate help if someone knows a solution.  My first post - hope I did this right.

    if its anything like my Sony, theres a button top left corner that upon each press i get an audible bleep and the AV inputs come up on screen, i then cycle down to whichever input i wish to select!
    in case your remote is different, the button on my remote has a square with a slightly smaller square just overlapping the first square.
    hope that helps?
    rgds Lee.

  • How do you restrict new line in input field or delete last char. in as3?

    Sorry, Noobie here!
    I have a text input box. If the enter key is pressed, a new line begins; thus making the previous line invisible unless the backspace key is pressed.
    So, if i type "1" into the input box, then hit eneter the number "1" becomes invisible, unless I hit back.
    Now, I still need the enter key because i have an event listener that calls a function once it is pressed, but i still need that "1" to be visible.
    So, I need one of either:
    To be able to restrict the input text field from creating a new line (making max line allowed= 1)
    or
    To delete the last character entered in the input text if the enter key is pressed.
    Both of these should have the same result, however I don't know how to do both.
    If anyone can help, i'd be very grateful!

    This worked! Thanks so much!

  • HOW to Restrict the input Help for 0MATERIAL in the BPS Layout

    Hi,
    I have requirement to Restrict the input Help for 0MATERIAL  in the BPS Layout.
    For Example if the Planning Package is Restricted to SALES ORGANISATION ( 3000 )  then the system shuold  check the 0MAT_SALES  where SALES ORGANISATION IS "3000" )AND PASS THE Material Numbers to the 0material list.
    I have Copied the standard Funtcion group  "UPF_VARIABLE_USER_EXIT"  to Z fucttion and have attached to Z Variabe as User Exit .
    this Variable is  Attached to 0material in the Planning Pakage. So tha now the 0MATERIAL is restricted to the variable which is having the User Exit.
    But how to acces the Values of Planning Package for which the Layout is bein Executed from this Z User Exit ???
    I Know how to restrict the input help, but my only problem is that how to get the values of Planning package through this User Exit.
    Please suggest if it is possible.
    Regards,
    Nilesh Labde

    Hi Nilesh,
    As I understand from your question,you know how to restrict but the issue is to know the value in the package with which you need to restrict.
    There are two tables which can help you finding the value used in package for sales organisation:
    1. UPC_PACKAGE
    2. UPC_OPTIOS
    How to use ?
    From UPC Package you will get one GUID, Hit the second table UPC_OPTIOS with this GUID.
    In field "FIELDNAME" enter the name of the characteristic whose value is req (sales organisation in your case)
    Hope this helps you
    Mann

  • How to get Requester Login information into the request dataset validator

    Friends,
    I need to check whether the requester is part of a group or not before submitting the request. If not I need to throw an error.
    Can you please let me know how to get Requester information.login into the request validator?

    Hi Thiago,
    I am getting the requester id from the requestData in the request data validator. Here is my full code for your reference.
    Bikash - I even tried with RoleManager service but still same error.
    public void validate(RequestData requestData)
    throws InvalidRequestDataException {
    tcUserOperationsIntf UserOppsIntf =Platform.getService(tcUserOperationsIntf.class);
    try
    tcResultSet result=UserOppsIntf.getSelfProfile();
    result.goToRow(0);
    String requesterID = result.getStringValue("Users.User ID");
    String userKey=result.getStringValue("Users.Key");
    System.out.println("Request Login:"+requesterID);
    if (isMemeber(getOIMGroupKey("testGroup"),userKey))
    System.out.println(requesterID+" is a Member");
    else
    System.out.println(requesterID+" is not a Member");
    String reason = "Note[REQUEST_SUBMISSION_ERROR].text:You are not authorized to submit this request.";
    throw new InvalidRequestDataException(reason);
    catch(Exception e) {
    e.printStackTrace();
    private String getOIMGroupKey(String GroupName) throws Exception
    String groupKey="";
    tcGroupOperationsIntf groupInstanceOps = Platform.getService(tcGroupOperationsIntf.class);
    HashMap searchFor = new HashMap();
    searchFor.put("Groups.Group Name", GroupName);
    tcResultSet results = groupInstanceOps.findGroups(searchFor);
    for (int i = 0; i < results.getRowCount(); i++) {
    results.goToRow(i);
    groupKey = Long.toString(results.getLongValue("Groups.Key"));
    System.out.println("GroupKey:"+groupKey);
    return groupKey;
    private boolean isMemeber(String groupKey,String userKey) throws Exception
    boolean member=false;
    try
    tcGroupOperationsIntf groupInstanceOps = Platform.getService(tcGroupOperationsIntf.class);
    long grpLong = Long.parseLong(groupKey.trim());
    tcResultSet grpResultSet = groupInstanceOps.getAllMembers(grpLong);
    for(int i=0;i<grpResultSet.getRowCount();i++)
    grpResultSet.goToRow(i);
    long usrKeygrp = grpResultSet.getLongValue("Users.Key");
    if (usrKeygrp==Long.valueOf(userKey))
    member=true;
    break;
    catch(Exception e) {
    e.printStackTrace();
    member=false;
    return member;
    }

  • How can you get your restrictions pascode unlocked if you forgot your password?

    how would you unlock your restrictions

    - If you are up to it see:
    How to reset forgotten Restrictions...: Apple Support Communities
      How to reset forgotten Restrictions...: Apple Support Communities

  • How to do the validation in sap xi (input file)

    hi,
    how to do the validation in sap xi (input file)?
    regards
    Ruban

    Hi Ruban
    There are no fixed set of validations.
    It all depends on the exact functional requirements. Most of validations revolve in XI around,
    1. Validation of madatory fields.
    2. Cross Referncing of data.
    3. Validation for data in some fields , etc
    refr the below links for few details regarding validation
    <b>File Validations in SAP XI – A Case Study</b>
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/99593f86-0601-0010-059d-d2dd39dceaa0
    refer this Blog
    <b>Validating messages in XI using XML Schema</b>
    /people/morten.wittrock/blog/2006/03/21/validating-messages-in-xi-using-xml-schema
    <b> Where to create logical validations  </b>
    Where to create logical validations
    <b> HTTP to File with source XML validation </b>
    HTTP to File with source XML validation
    Thanks!!
    Regards
    Abhishek Agrahari

  • How do you choose songs from your ipod instead of from the car dashboard while your ipod is plugged into your car?

    How do you choose songs from your ipod instead of from the car dashboard while your ipod is plugged into your car?

    It depends on your car stereo. On the JVC we have you can select either "Head Mode" or "iPod Mode" when you're plugged into the USB port. Ipod Mode lets you select the songs from the iPod although the radio still controls the volume. I believe the Alpine I have does the same thing.

  • How to restore your restriction passcode on an ipad

    how to restore your Restriction passcode on an ipad?

    To remove the Restrictions passcode you will need to either...
    Restore the Device as New...
    http://support.apple.com/kb/HT4137
    OR...
    from a Backup created Before the Restrictions Code was set....
    http://support.apple.com/kb/HT1414

  • How to save User input into DB using webdynpro abap

    Hi,
    Im trying to create an application using webdynpro abap.
    I want to know how to save the data input by user, into a database table.
    In my UI, I have a table control which is editable and user inputs data into this. I need to know how i can transfer this data to a DB table.

    hello,
    u can do it by reading ur context node.
    we bind our UI elements to context attributes of appropriate type .
    we read their values using the code wizard or by pressing control+F7, click on radio button read node/attribute
    here for ur specific case , u must have binded ur table control with the context attribute , now u need to simply read this attribute
    eg suppose u have created a context node " cn_table"
      reading context node cn_table
       DATA : lo_nd_cn_table TYPE REF TO if_wd_context_node ,
             lo_el_cn_table TYPE REF TO if_wd_context_element ,
             ls_cn_table    TYPE wd_this->element_cn_table.
    *   navigate from <CONTEXT> to <CN_TABLE> via lead selection
      lo_nd_cn_table = wd_context->get_child_node(
                       name = wd_this->wdctx_cn_table ).
    **    get element via lead selection
      lo_el_cn_table = lo_nd_cn_table->get_lead_selection(  ).
      lo_el_cn_table->get_static_attributes( IMPORTING
                 static_attributes = wa_table ).
    here wa_table is the work area of structure type . u need to create a structure first with the same variables as there are the context attributes in ur node cn_table
    in ur
    now ur wa_tablecontains value
    u can nw use appropriate FM to update , delete and modify the DB table using the value
    u cn directly use SQL statements as well in the method of ur view , but direct SQL statements are nt recommende
    rgds,
    amit

Maybe you are looking for