How to Make JTextField Accept Only Specific Numbers?

Hello There
I've made 3 JTexfields That accepts only Numbers
But I Want To Make Them Accpets Numbers only from 1 to 12
and if the number is greater than 12 they don't accept it?
another Thing That I've Set Their Columns To 2 meaning that i want the user to enter only two numbers
but yet the user can enter many numbers how would i restrict entering numbers to only two numbers?
here's my code:
  import java.awt.*;
  import javax.swing.*;
  import javax.swing.text.*;
  public class ManyText extends JFrame{
       public static void main(String[]args){
       JTextField[ ] text = new JTextField[3];
       JButton button=new JButton("Press");
    for(int i = 0; i < text.length; i++)
     text[i] = new JTextField(3);
     for(int i = 0; i < text.length; i++){
     text.setColumns(2);     
text[i].setDocument(new PlainDocument(){
public void insertString(int offs, String str,
AttributeSet a) throws BadLocationException{
if("0123456789".indexOf(str) < 0)
java.awt.Toolkit.getDefaultToolkit().beep();
return;
super.insertString(offs, str, a);
     JFrame f=new JFrame();
     f.setSize(200,200);
     f.setLayout(new FlowLayout());
     f.add(text[0]);
f.add(text[1]);
f.add(text[2]);     
     f.setVisible(true);     

ejp wrote:
Actually I would suggest you're using the wrong control. I would use a JComboBox or a JSpinner for this.I suggested he use a JSpinner 1-2 threads ago. Maybe if he hears it enough, he'll believe it.

Similar Messages

  • Nokia 5610 - how to make calls ring only on headph...

    Nokia 5610 - how to make calls ring only on headphone and not on phone???
    Could someone help me out please??? I tried everything... Nothing works!!!

    Surely if you put the phone on silent and connect the headphone? That works on mine.
    Chris
    6230i (the last bug-free Nokia?)
    Vodafone UK contract since 1992

  • How to make a page break in numbers

    The only way I found to make a new page in Numbers was to make new rows down to where the page would break, but it's only letting me add a few new rows to the new page.  I'd like to know how to make a page break without just adding rows.

    Hi Yellowbox,
    Still I'm not convinced, it gives you indeed some advantages but this page break is a great fault.
    All the company is working on Apple, we try even to keep Microsoft away but what when you make a quote of several pages and have to make your lay out at the end, it is a pain in your xxx to make it well.
    We cannot make different tables for each page nor I want to make it in Pages with a Numbers table.
    Secondly, what do you do when you get a Excell offer that you want to bring to Numbers.
    It opens well but again, you need to make all the page lay out afterwards!
    Thanks for yoru reply.
    It won't change my mind about Apple and Microsoft but for timing earning I won't changes all Excel offers to Numbers anymore. Even if I do not want, it would take me less time to work it out in Excel.
    Our own offers will remain in Numbers ...
    It is a pity but time is so important nowadays!
    Nice week-end.

  • How to make a simple program in numbers that i can use on my iphone

    how can i make a touchable program in numbers that i can trasfer to my iphone and use out in the field of work? i am pretty good at excel sheets,but am still new with my macbook.

    Excel can't make an iPhone application, it can only make a spreadsheet. You would need an iPhone app capable of reading a spreadsheet produced by Excel.

  • How to make F-02 only can "park" , not "post" .

    Use F-02 to key FI document , how to make it only can "park" , not "post" .
    I  try to use "PFCG" to find whether any "Authorization object"  to control it ,but i didn't find.
    anyone can help me ? Thank you !
    http://file.itpub.net/forum/201112/07/1518204gdl7ylj0pz1117m.jpg

    Hi:
        Authorization object F_BKPF_BES is used to detain this. If you revoke activity 01 out against a particular GL Authorization group as assigned in F_BKPF_BES , user would not be able to post the transaction. He will only be able to park ..However if you want to make it t code specific then please make use of screen variant and disable the post button in F-02.....
    Regards

  • How to make jTextField 's input unscrollable?

    Dear All
    i create a JTextField, i want to set it inputsize = 5(charaters)
    i am doing like this
    JTextField jTextField = new JTextField(5);
    jTextField.setScrollOffset(0);
    but it doesnot work out
    it is still scrollable, i main i could input more than
    5 charaters
    How to fix JTextField's input size?
    Thx in advance

    Hi,
    that does not change the amount of characters, you can input, it only says, that the JTextFields-size should be 5 times as wide as an average char.
    If you want to limit the characters you will have to replace the Plaindocument JTextFields uses internally with a subclass of it, that overwrites its insertString(...)-method. An example, that makes all input upcase is found in the documentation of JTextField. You can do your checking in a similar way there - just checking if the length of the string to insert plus the length of the text that is currently in the box is greater than the maximum length - if it is not, pass all parameter simply to the super.insertString(...)-method - if it is greater, that only do a Toolkit.getDefaultToolkit().beep().
    Also there are many topics dealing with this stuff - please search the forum for it.
    greetings Marsian

  • How to make DFF Read Only ..

    Dear Friends,
    I have 3 segments in the Additional Personal Details DFF in HRMS. I want to make only the 2nd segment read-only not all the segments.How can we achieve this can any one pls let me know about this ...
    with regards
    Swpana

    Hi,
    Review the following documents and see if it helps.
    Note: 438215.1 - How To Make DFF Segments Read Only Using OAF Personalise
    https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=438215.1
    Note: 750679.1 - How To Make Only Some Of The Segments Of A Descriptive Flexfield Read Only On OA Framework
    https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=750679.1
    Note: 149452.1 - How do you make a descriptive flexfield display only?
    https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=149452.1
    Regards,
    Hussein

  • SRM 7 Header Delivery Tab-- how to make fields read only

    Hi Experts,
    We are upgrading from SRM 4 to SRM 7.
    In SRM 7
    Create Shopping Cart--> In General Data Click the link Set_Values --> Go To Delivery Address/Performance Location tab
    All the fields here are input ready, how can we make these read only?
    Thanks a ton
    Anubhav

    Please I need help too on this :
    When I try to create a SC I get the default address as below which was the og unit address :
    It is picking the address from the Org unit :
    Now If I check the user attributes That I have now added address number data should have been populated .   The attributes address are also seen correctly below in the attributes section below :
    The attributes address are also seen correctly below in the attributes section below :
    However when I create a SC 1001000515 created in test it has Delivery address as blank stored :
    Please can soe  one guide me is this a bug ?

  • How to make fields Read only on all tabs in one go with the help of feeder classes in SAP EHS?

    I have a requirement where once we press SAVE button i have to make all the fields read only in tabs highlighted below.Which is the best method to do it.?
    There are number of fields in all these tabs and we want to make them read only on particular Action event.How to do it?
    Thanks,
    Vimal

    Hi Vimal,
    As I understood you reformulate this question at this page. I will try to help you there.
    Kind regards, Aliaksandr.

  • How to make OAM accept SAML Assertion?

    Hi folks,
    I need to make OAM accept SAML Assertion. We have a Layer7 appliance called SSG (Secure Span Gateway) which protects web resources and generates SAML assertion. I need to find out whether OAM can accept the SAML Assertion sent by SSG appliance to authenticate and authorize access.
    Any help is appreciated.
    Thank you, Roman

    Hi idmgod,
    Thanks for the post. Rather interesting! Correct me if I'm wrong here, but this is how this should work:
    1. The simpleSAMLphp (configured to support php w extensions, connect and authenticate/authorize against ldap server in my case, etc) sits in front of OAM, and accept the SAML Assertion
    2. It then creates an obSSOCookie (just like the WebGate does), and sends it to OAM
    3. OAM checks obSSOCookie and based on the cookie data (user DN, shared secret key, etc) allows access to a protected resource
    Does this sound right?
    Roman

  • How to make stork table in Mac numbers

    hello,
    how how to make stork tables in numbers just as what we can creat in windows excel?
    thank you

    Another way to create this type of chart is to create the pieces in separate charts and then layer them. 
    You create two stacked bar charts.  There are two rows of values in each.  The color of the bottom value is set to "no fill" to create the floating bar effect. 
    The width of the stick bar is changed by setting the gap to the maximum allowable (999%).  The "stick" chart is placed behind the other.
    For this to work, they need to be the exact same size and with the same axis values.  Setting the axis to have fixed values makes this easier.  Also, it improves the appearance to limit all the axis labels and lines to be in just one of the charts.

  • OA Framework,how to make field Read-Only which is used inside Switch case

    Hi all,
    Using Personalization in OA Framework, when I am trying to make field read only, which is inside Swich statement ,then that field get automatically hidden.but my purpose is to make that field read-only not hide.
    My field name is Proposed Annual Increase Amount .
    The Personalization swtich case lookslike this :-
    Field Name Shown
    Switcher: Proposed Annual Increase Amount Yes
    case_name_HrPRateAnnTotInputSs
    Message Text Input: New Annual Amount Yes
    case_name_HrPRateAnnInputSs
    Message Text Input: Annual Pay Rate Yes
    case_name_HrPRateCurrAnnSalSs
    Message Styled Text: Pay Rate
    Regards,
    Mxj2930

    Can you be a bit clear on your requirement. If you have a switcher to display a field based on some condition, the other fields will not get displayed. I did not get as to what you mean by "my purpose is to make that field read-only not hide.".
    Are you talking about the case, when the "New Annual Amount" (or) "Annual Pay Rate" fields are displayed conditionally, you want them to be read-only and not editable. If this is the case, set the read-only property of these fields to true.

  • How to make files read only

    I want to make files read only.  Any workaround is welcomed.

    t quinn wrote:
    ElMagoElGato,
    I am glad to give some help but I am still confused because we are having different experiences. I have been able to lock Tables on my mac and have that lock respected in iOS for a long while now. Easy to unlock, impossible to relock.  With the most recent upgrade I can lock tables after tapping the upper left dot to select the whole table and going to "arrange" in the paintbrush.
    When you say worksheet are you meaning the entire file? When you say file lock are you meaning password protection? You can see I am confused.
    quinn
    Based on what ElMagoElGato has described, password protecting would be of no value to him. Once the file is accessed, it is in edit mode. Unless I'm really missing something.
    Files I have imported from Mac iworks apps with elements locked stay locked for me in iOS. Not sure what the problem is.

  • How to make JTextArea read only

    I want to make JTextArea read only so that you can only append text at design time and not at run time and so the user can not delete text in the text area.

    You can use the setEditable(boolean) method. I think that it's the best way.
    Sebastien

  • [SOLVED] How to make file read only and stay?

    I'm using gnome 3 and want to make the recently used.xbel file (in .local/share) read-only/locked. I've tried making it read only and it just reverts to normal when something tries to write to it. How do I do this?
    Last edited by sudokill (2011-04-29 19:41:51)

    Worked great, thanks. No more recent documents at all

Maybe you are looking for

  • HP Pavillion Does NOT work Straight Out of the Box after Purchase

    My daughter bought a new HP Pavillion from Office Depot before starting computer classes at the university.  The first one would not work at all and after the tech folks tried all that they could and it would not work, the Office Depot staff exchange

  • HP Pavilion TouchSmart 14-b109wm Sleekbook will not boot up

    My HP Pavilion TouchSmart 14-b109wm Sleekbook will not boot up windows. upon power it goes to a blue screen that reads "Recovery" your pc couldnt start properly. Error code 0xc0000185. Youll need to use the recpvery tools on yout installation media I

  • No pics appear in iphoto and aperture sidebar since iLife 11

    With the update of iLife11 the pics disappeared from the sidebar under iPhoto and Aperture. While the sidebar for Audio, Movies and Widgets runs well, only the running upload icon appears beside of iPhoto and Aperture. Why does iWeb not find the pics

  • Enhancement SRVDET in T-Code ML81N

    Hi, My requirement is to add certain custom fields in T-Code ML81N. For this I am using the Enhancement SRVDET - User screen on tab strip of service detail screen. I have added the fields in Table CI_ESLLDB. and then mapped these Custom fields in the

  • Nokia email client and yahoo small business proble...

    Hi All, I have been using nokia email client for more than a year and it was working perfectly fine until some days ago. I updated my email client with latest build and now it is not fetching/pusing email for yahoo small business email address. I hav