Preventing user to enter chars in a JTextField

Hello,
I'm working on a small "calculator" applet. I'm pretty much done, except for a couple of problems:
First I would like to prevent the users to enter non-numeric characters in the JTextField where the numbers go, but I have no idea how to go about that.
The other thing is that all my JButtons don't show their set text (like +,-,/ , etc) instead they all show "..." , as if the text was too big for the button. I can get the text to show if I enlarge the buttons enough, but I end up with insanely large buttons, and the text is in reality quite small. Any way to decrease the size of the text inside the button? (i'm using setBounds() for positions and sizes by the way).

Hello,
I'm working on a small "calculator" applet. I'm
pretty much done, except for a couple of problems:
First I would like to prevent the users to enter
non-numeric characters in the JTextField where the
numbers go, but I have no idea how to go about that.See JFormattedTextField and MaskFormat in the JavaDocs.
>
The other thing is that all my JButtons don't show
their set text (like +,-,/ , etc) instead they all
show "..." , as if the text was too big for the
button. I can get the text to show if I enlarge the
buttons enough, but I end up with insanely large
buttons, and the text is in reality quite small. Any
way to decrease the size of the text inside the
button? (i'm using setBounds() for positions and
sizes by the way).Don't. Use a LayoutManager. For a calculator, a group of nested GridLayout Panels should work.
Jim S.

Similar Messages

  • Prevent user from entering info in a JTextField

    I have implemented a calculator in a GUI.
    At the moment it works but the user can enter text in the answer JTextField.
    I want the answer to appear in a JTextField (background to appear grey) when a Jbutton 'equals' is pressed but I want to prevent the user from being able to enter anything in this field, so that it is only an output field. Is there a special way to disable input from JTextFields?
    Thanks in advance!

    Is there a special way to
    disable input from JTextFields?Take a look at:
    setEditable(false); and
    setEnabled(false);
    /Kaj

  • How to prevent user from entering zero hours in Timecard

    We have a need to prevent user to enter/submit zero hours in timecard. The case right now is user will be able to enter:
    Hours Type M T W T F
    Vacation 0 8 0 0 0'
    and when we run BEE transfer process it created absences with zero hour duration for Monday, Wednesday, Thursday and Friday.
    We try to prevent absences to be created with zero hours or user to be able to enter zero hours in timecard.
    Please help.
    Thanks

    Hi
    you can refer following example
    ========= formula ===============
    Initialise Variables which can be null
    default for db_pre_period_start is ' '
    default for db_pre_period_end is ' '
    default for db_post_period_start is ' '
    default for db_post_period_end is ' '
    default for db_ref_period_start is ' '
    default for db_ref_period_end is ' '
    READ IN INPUT VARIABLES
    INPUTS ARE resource_id (number)
    , submission_date (text)
    , period (number)
    , period_maximum (number)
    , reference_period (number)
    , db_pre_period_start (text)
    , db_pre_period_end (text)
    , db_post_period_start (text)
    , db_post_period_end (text)
    , db_ref_period_start (text)
    , db_ref_period_end (text)
    , duration_in_days (number)
    , timecard_hrs (number)
    Processing
    l_return = otl_24_hours_check()
    IF l_return > 0 THEN
         ( rule_status = 'E'
         message1 = 'DAILY_MAX_LIMIT' )
    RETURN VARIABLE
    RETURN rule_status, message1
    ============= database package ==============
    FUNCTION otl_24_hours_check
    RETURN NUMBER IS
    j NUMBER := 0;
    e_count NUMBER := 0;
    tc_blocks Hxc_Self_Service_Time_Deposit.timecard_info;
    BEGIN
    tc_blocks := Hxc_Self_Service_Time_Deposit.get_building_blocks;
    j := tc_blocks.FIRST;
    WHILE j IS NOT NULL
    LOOP
    BEGIN
    IF tc_blocks(j).scope = 'DETAIL' THEN
    IF to_number(tc_blocks(j).measure) > 24 then
    e_count := e_count + 1;
    END IF;
    END IF;
    j := tc_blocks.NEXT(j);
    END;
    END LOOP;
    RETURN e_count;
    END;
    ================================
    above formula checks if a person entered more than 24 hours in a day

  • How to prevent users from entering '+' or '0' in front of country code in the phone number field?

    Requirement:
    How can I prevent guest users from entering '+' sign or '0' in front of country-code in the visitor phone number field during self registration?
    Few SMS service providers are not looking for '+' sign or '0' or '00' in front of the international phone numbers to trigger the sms. Providing these values in front of country code during self-registration may fail to deliver the sms to recipient.
    Solution:
    Using a simple regular expression, you can validate the entered phone number during the guest registration. 
    The below regular expression will help you to validate the phone number and allows to register only  when the phone number is not staring with '+' or '0'. 
    ^[1-9][0-9](\d{7}|\d{8}|\d{9}|\d{10}|\d{11}|\d{12})$
    It also performs the below validations.
    only numbers are allowed.
    first digit of the entered phone number should be 1 to 9, so '+' or '0' is not allowed. 
    numbers from 0 to 9 are allowed from the second digit.
    also validates phone number length, the length of the phone number should be 9 to 14.
    Configuration:
    To add the above regex in the visitor_phone number filed, please navigate to ClearPass Guest >> Configuration >> (Pages)Guest Self-Registration >> select the self-registration page and go to Edit >> Register Page >> Form >>  select the filed visitor_phone and set the Validator to " ISRegexMatch" and enter the above regex in the Validator Argument filed as shown below.
    Note:  Edit the Validation Error as per your requirement.
    Verification
    Adding the given regex will validate the phone number and prevent the guest user from registering the phone number starts with '+' or '0'.
    Please find below the sample outputs for your reference.
    Result when phone number starts with '+' or '0'.
    Successful registration.

    Is this a Mac Preview issue?

  • How to prevent user to enter data in "Date/Time Field"?

    Hi folks,
         Back after long time to the forums, where I get answers which are helpful in making me good at utilizing designer.
         I am trying to validate the "Date/Time Field" using JavaScript but couldn't get a proper RegEx expression for various invalid user input formats. If anyone can help me out in finding a proper script that would Great.
         My script grown bigger and bigger to accepting invalid dates, but felt like hardcoding. So, instead I decided why can't we prevent a user to enter data into "Date/Time Field" and use only calendar dropdown. Is there is a way to do this?
    find my sample testing docment
    https://acrobat.com/#d=mYXkrhO2txuEesCfmvxNXg
    Thanks in Advance,
    Rajesh

    Hi Rajesh,
    I don't think there is a way of stopping the user from using the keyboard to enter a date.  You can use the following script in the change event to stop them typing a date but they will still be able to paste a date in.
    if (xfa.event.change.length === 1)
    xfa.event.change = "";
    This code works because if the date is selected from the calendar dropdown then the date xfa.event.change value will be the whole date and therefore longer than one character.
    I couldn't access your sample but if you were to set an display picture for the date field to something other than date{YYYY-MM-DD} then a valid date will have a formattedValue that is different than the rawValue.
    Dave

  • Prevent User From Entering Characters In A TextField

    Does anyone know how to prevent certain kinds of letters or symbols from being entered into a textfield? Something that prevents the user from typing a minus sign or the letter Q.

    You can also use KeyListener. You can also search the forum as this question has been asked numerous times.

  • [SOLVED] Faces - Preventing user from entering URL manually

    Hello,
    I know somewhere in this forum is thread about this issue but I'm not able to find it.
    I want to redirect or forward user to start page when he/she enters URL manually.
    Any ideas?
    Rado

    Hi,
    You can tell whether a request is from the browser URL or JSF by the access method: POST or GET
    The following doFilter() method is from a ServletFilter you can add to teh Faces Servlet in e.g. SRDemo
    public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain chain) throws IOException, ServletException {
    if (((HttpServletRequest)request).getMethod().equalsIgnoreCase("GET") &&
    !((HttpServletRequest)request).getRequestURL().toString().endsWith("SRWelcome.jspx")){
    _filterConfig.getServletContext().log("User "+((HttpServletRequest)request).getRemoteUser() +" doesn't play by the rules !");
    chain.doFilter(request, response);
    It checks for the access method and if it is GET and the accessed page is not SRWelcome then it logs the username to the application log. (You may want to do someting different here).
    The problem is however that you application (JSF) should not use "redirect" on its navigation case because this also sends a GET request.
    This filter works fine but would fail if e.g. you need to have fine grained authorization based on URL patterns. In this case, the patterns need to be added to the exclusion list because J2EE security requires you to redirect a request to be effective.
    Frank

  • JTextField: delete last entered char

    how can i delete the last entered char in a JTextField.
    In my textfield a Person can only enter 5 Chars. If you enter mor than 5 chars, the chars behind the 5th position must be deletet an the caret must stay behind the 5th char.
    How can i do this in java??
    Java let always stay the last typed char behind my string, i cant remove it.
    2.Question: with the method .getText() i get a String, but the last pressed key is not in that string
    how can i make it right??

    First Construct this method
         public static void setLenText(java.awt.event.KeyEvent event,int len){
         if (event.isConsumed())
    return;
    char c = event.getKeyChar();
    JTextComponent source = (JTextComponent )event.getSource();
    if (source.getText().length() >= len &&
    event.getKeyChar() != event.VK_BACK_SPACE &&
    source.getSelectionStart() == source.getSelectionEnd())
    source.getToolkit().beep();
    event.consume();
    then in the KeyTyped event of the textfield:
    void JTextField_keyTyped(java.awt.event.KeyEvent event)
              GlobalMgr.setLenText(event,5);
    By

  • How to prevent a user from entering characters into a number field

    How do you prevent a user from entering characters like A or B into a field that is defined as a numeric field?
    Please note that
    - we use block validation (for other reasons)
    - we are not able to convert these numeric fields to character fields
    We want to avoid a user being hasseled with the FRM-40209 ... message.
    This message is
    - not very helpfull because it does not inform us what the problem field is
    - not suppressable
    Any hints ?

    I went back to the drawing board on this one.
    You are absolutely right : the message can be catched !
    By writing an on-error trigger you can check for the error number. Sadly enough my first attempt on this used the on-message trigger which never fired hence my desperation.
    Anyway, the on-error trigger in combination with :SYSTEM.CURRENT_ITEM or :SYSTEM.TRIGGER_ITEM enables me to display a more meaningfull message to my users.
    Thanks for the hint.

  • How can we prevent a user from entering a value in Parameter Field?

    how can we prevent a user from entering a value in Parameter Field and Select-options Field?

    make it invisible, make it inactive, make it display only.
    if the field is not there or not to be seen the user WILL have problems inputting data.
    BUT once the field is there you can NOT prevent that the user fills it with data.
    all you can do is on PAI check if the data the user inputted was good or bad, and clear his inputs, but you can NOT prevent him inputting something.

  • 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

  • How can I get user to enter date & time on a form?

    I have a form where I want the user to enter a date and time for an event. The database field is in MYSQL datetime format
    I've used the datepicker on the form field but it only allows for a date entry not time.(eeven when seetin the width to 22 chars
    I remember doing something before which allowed the user to pick a date and then add the time at the end.
    I've got the date defaulted to dd/mm/yyyy and the time to H:mm in the control panel.
    Can anyone help please or is there a better way to enter date and time?.
    Any help appreciated
    Thanks
    Clive

    Two things:
    The column in your database is defined as DateTime, not Date
    You use the option on the Date Picker to choose datetime, not date
    This will give the user the ability to choose a date and time from the date column.  If you need more control over the time, you probably need to add another column defined as Time.  Then you can use the validation rules to force an entry rather than allowing the default (current time).

  • Why am I receiving a notice to update my version and then not able to click on it? It also prevents me from entering the internet if I put my computer to sleep with this update box there!

    The box appears after I'm on the internet. It's on my desktop when I go to shut down my computer and after I've shut down the internet. When I click on the x it doesn't disappear. When I click on the box indicating Yes, I'd like to update my version of Firefox it does nothing. If I leave this box there and put my computer to sleep it stays on and actually prevents me from entering the internet! I need to restart my computer or shut down! My computer is a MacBook Pro and is only one year old .

    They have to know who the person is who has their account set up wrong?   Do you know who they are or how to identify them?
    if not, how do you expect Verizon to find which user that is?
    Best thing for you to do is set up a mail filter and just throw those into the trash or delete them the second they come into your email box. 
    here are a couple walk throughs. 
    How to Filter Mail from a Certain Sender Easily in Win Live Mail, Outlook Expr.

  • Sharepoint 2010: prevent users from editing a list in the datasheet view

    Hi,
    I have a sharepoint 2010 list that I need to prevent users to edit from the datasheet view. This is because I have edited the add item form on sharepoint designer and included some custom code. Moreover, I need to allow the users to view the list in datasheet
    view to make use of the datasheet custom filter view feature which is not available in the standard view. So I need users to access the datasheet view of the list in read mode only but be able to edit the list in standard view only. Is this possible? How?
    Thanks,
    George

    Hi.
    Maybe this helps...I found some users having the problem that the list WAS read only in datasheet view...this is a list of reasons why this could happen:
    Certain columns, such as Created By and Modified, are always read-only. Values for these columns are entered automatically.
    The changes you made to the selected row or column have been submitted to the server. If there is no conflict or error, you will be able to edit the row or column after the changes have been saved.
    There is an unresolved conflict or error in the selected row or column. Resolve the conflict or error before attempting to edit the selected row or column.
    The list is set up to require content approval, and you are viewing the list in the All Items view.
    In the My Submissions view of a list that requires content approval, the
    Approval Status and Comment column are read-only. Only a user with Manage Lists right can edit these two columns.
    Attachments are read-only in a list that requires content approval. You cannot view or edit attachments in any of the views.
    The document in the current row has been checked out by a user. You cannot edit the columns in the row until the user checks the document in.
    You do not have permission to edit the column or row. Contact the list author for more information.
    (from the help)
    You could also check:
    http://support.microsoft.com/kb/2274841
    Reverse engineer and you may have a solution? ;-)
    Regards
    hr class="sig">Thomas Balkeståhl - Technical Specialist - SharePoint

  • How to prevent user from "normal" navigation?

    Hi everyone,
    I have a PDF with a lot of pages, which are connect through Links (It's an export from MS Visio).
    I now want all the users to keep navigating through the links and prevent accidental navigation through the "normal" way (Arrow-Keys, Mouse-Scroll, etcs...) as much as possible.
    For this I have three ideas:
    "Force" Fullscreenmode: Here I can prevent from advancing in pages by clickAdvances=false. However I think it's not possible to prevent page changes by mouse-scroll or key-press.
    Using Layers: I have read, that it is possible to show/hide layers on demand with js. But I don't know how this can be done. And I would have to change the links to js-function showing the needed layer...
    Loading/Deleting Pages: I could load and delete Pages on demand. This is probably slow and i would need two pdf files.
    Does anyone knows something that could help me to solve this problem?
    Cheers, Holger.

    1. Not possible (except if the additional method described below is used).
    2. This is possible, but it requires setting up the layers and then a system of buttons and scripts to show/hide them.
    3. Also possible, but much more complicated than using layers.
    Another option is to use a script to prevent the user from entering a page, unless its done via a button.
    However, all of these methods have their disadvantages and can be very annoying for the users. You should really think if you want to implement this feature...

Maybe you are looking for