How will  the typed character in a textField not be printed

Hi all, I want to trap the typed characterfrom the user in a txtField. If
the character is not digit it will not be printed in the componet. I used
keytyped event with the folloing code...
      char typedChar = e.getKeyChar();
      String currText =txtFldMsBdIndxWeight.getText();
      if (!Character.isDigit(typedChar))
         if (currText.length()!=0)
            currText = currText.substring(0, currText.length()-1);
            txtFldMsBdIndxWeight.setText(currText);
        else  txtFldMsBdIndxWeight.setText("");
      the problem is when the text of the componet is empty (currText.length()==0)
the non digit character will be printed in the componet, the code...
txtFldMsBdIndxWeight.setText("");is not working.
What am i doing wrong thank you for advance,
Kostas

Here is the JNumberField implementation for you
Ashish
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.text.*;
* <P>This Class is used to create number Text Field
public class JNumberField extends JTextField {
private boolean isReal=false;
private int digitCount;
private boolean copyPasteSupported=true;
* <P>This is a default constructor.It creates text field with length of 10 , right aligned and
* without decimal point
* @param
* @return
public JNumberField()
this(10,RIGHT,false);
* <P>This constructor creates text field with specified length , right aligned and
* without decimal point
* @param integer digitCount indicates the length of the text field
* @return
public JNumberField(int digitCount)
this(digitCount,RIGHT,false);
* <P>This constructor creates text field with specified length,specified aligned and
* without decimal point
* @param int digitCount indicates the length of the text field
* int alignment indicates the alignment.It can be LEFT or RIGHT
* @return
public JNumberField(int digitCount,int alignment)
this(digitCount,alignment,false);
* <P>This constructor creates text field with specified length,specified aligned and
* flag to assign decimal point
* @param int digitCount indicates the length of the text field
* int alignment indicates the alignment.It can be LEFT orRIGHT
* boolean isReal flag to set decimal point
* @return
public JNumberField(int digitCount,int alignment,boolean isReal)
this(digitCount,alignment,isReal,false);
* <P>This constructor creates text field with specified length,specified aligned and
* flags to assign decimal point and to support copy paste operation
* @param int digitCount indicates the length of the text field
* int alignment indicates the alignment.It can be LEFT or RIGHT
* boolean isReal flag to set decimal point
* boolean copyPasteSupported flag to support copy paste
* @return
public JNumberField(int digitCount,int alignment,boolean isReal,boolean copyPasteSupported)
setDocument(new NumberDocument());
setDigitCount(digitCount);
setHorizontalAlignment(alignment);
setReal(isReal);
setCopyPasteSupported(copyPasteSupported);
addKeyListener(new JNumberFieldKeyAdapter());
* <P>This method sets the flag to support copy paste operation
* @param boolean copyPasteSupported flag to support copy paste
* @return
public void setCopyPasteSupported(boolean copyPasteSupported)
this.copyPasteSupported=copyPasteSupported;
* <P>This method checks the copy paste is supported
* @param
* @ return boolean copyPasteSupported flag
public boolean isCopyPasteSupported()
return copyPasteSupported;
* <P>This method sets the Real Value support flag
* @ param boolean isReal flag to set the Real value
* @ return
public void setReal(boolean isReal)
this.isReal=isReal;
* <P>This method checks whether Real Value is accepted
* @param
* @ return boolean isReal flag
public boolean isReal()
return isReal;
* <P>This method sets the text alignment
* @param int alignment value can be LEFT or RIGHT
* @return
public void setHorizontalAlignment(int alignment)
if(alignment==LEFT || alignment==RIGHT)
super.setHorizontalAlignment(alignment);
* <P>This method gets the no of digits of text field
* @param
* @return int digitCount
public int getDigitCount()
return digitCount;
* <P>This method sets the no of digits of text field
* @param int digitCount of text field
* @return
public void setDigitCount(int digitCount)
this.digitCount=digitCount;
* <P>This is an inner Class which overrides the Document Class
public class NumberDocument extends PlainDocument {
* <P>This method overrides insertString method of PlainDocument Class
* @param int offset - The Location of a String to be inserted
* String String str - The String to be inserted
* AttributeSet a - Attributes of a text Field
* @return
* @Exception throws BadLocationException when the offset value is negative or exceeds the
* length of the text field
public void insertString(int offset, String str, AttributeSet a) throws BadLocationException
if((getLength()+1) >getDigitCount())
return;
if(str.length()==1)
if(Character.isDigit(str.charAt(0)))
super.insertString(offset,str,a);
else
if(str.charAt(0)=='.' && isReal())
if(JNumberField.this.getText().indexOf('.')<0)
super.insertString(offset,str,a);
else
boolean isStringContainsChar=false;
for(int i=0;i<str.length();i++)
if(!Character.isDigit(str.charAt(i)))
isStringContainsChar=true;
break;
if(!isStringContainsChar)
super.insertString(offset,str,a);
* <P>This is an inner Class which listens the Key Events
public class JNumberFieldKeyAdapter extends KeyAdapter {
String textBeforKeyPressed="";
* <P>This method captures the Key Event and prevents the copy paste operation
* if copy paste is not supported
* @param KeyEvent ke - captured Key Event
* @return
public void keyPressed(KeyEvent ke)
char keyChar=ke.getKeyChar();
if(keyChar=='\r' || keyChar=='\n')
System.out.println("EnterPressed ");
String modifire=ke.getKeyModifiersText(ke.getModifiers());
if((modifire.equalsIgnoreCase("Ctrl") || keyChar=='v' || keyChar=='V')&& !isCopyPasteSupported())
ke.consume();

Similar Messages

  • How will the system handle delta in the below scenario

    How will the system handle delta in the below scenario
    Day 1
    DS--->DSO
    PSA
    Document Number| Customer | sales value
    1001| RAMLAL | 10000
    Your change log for DSO will read
    Req1| 1001|RAMLAL|10000|N
    DSO(overwrite)
    1001|RAMLAL|10000|
    Day 1
    DSO--->Cube
    Req1| 1001|RAMLAL|10000|
    Day2
    DS--->DSO
    PSA
    Document Number| Customer | sales value
    1001| RAMLAL | 30000
    Your change log for DSO will read
    Req2 | 1001 | RAMLAL | -10000 | X
    Req2 | 1001 | RAMLAL | 30000
    DSO(Overwrite)
    1001 | RAMLAL | 30000
    Day 2
    DSO--->Cube
    Req1|1001|RAMLAL|10000|
    Req2|1001|RAMLAL|20000|
    Please explain with example
    Scenario 1: Req1 & Req2 are deleted ONLY from change log on Day 3
    On Day 4:
    DS--->DSO
    Document Number| Customer | sales value|STOR_NO(ROCANCEL)
    1001| RAMLAL | 10000|C
    What will happen to the Sales Value in the cube?
    What will happen to the Req1&Req2 in the cube?
    Thanks
    Tanya

    Tanya,
    Please explain with example
    Scenario 1: Req1 & Req2 are deleted ONLY from change log on Day 3
    On Day 4:
    DS--->DSO
    Document Number| Customer | sales value|STOR_NO(ROCANCEL)
    1001| RAMLAL | 10000|C
    What will happen to the Sales Value in the cube?
    What will happen to the Req1&Req2 in the cube?
    Document Number| Customer | sales value|STOR_NO(ROCANCEL)
    1001| RAMLAL | 10000 |C
    --> Here 1000 is not correct value, as 1000 is change to 3000. It should be 3000. record should be as below.
    Document Number| Customer | sales value|STOR_NO(ROCANCEL)
    1001| RAMLAL | 30000 |C
    --> As this data related to sales, and i hope you are using standard ABR extractors(Business Content).
    ABR datasources delivers before and after images.
    Before image:
    Document Number| Customer | sales value|STOR_NO(ROCANCEL)
    1001| RAMLAL | -3000 |C
    Before image:
    Document Number| Customer | sales value|STOR_NO(ROCANCEL)
    1001| RAMLAL | 0 |C --> value changed from 3000 to Zero.
    If you are loading in additive or Overwrite into an ODS total sales for 1001 at end of day 4 will be Zero.
    Hope it helps
    Srini

  • How find the Special Character Table?

    Hi friends.
    i need table for special characters. how find the special character table.
    example : &,@<#<$ -- all are special characters.
    any body please reply immdly.
    regards
    pauldharma

    Hi Raj,
    Check this forum thread:
    Print Currency as symbols in SAPSCRIPT/Smartforms
    Hope this helps.
    Regards,
    Vivek Myadam

  • How will the Adobe Certified Expert program be managed with the shift to Creative Cloud?

    I am presently studying to certify as an Adobe Certified Expert/Adobe Certified Instructor in Photoshop, Illustrator, and InDesign. My studying has been based upon the CS6 versions.
    How will the ACE program work once we switch to CC? Should I wait for more changes to the program before taking my exams?
    Thank you!

    Hi Dreia, denniR,
    We will offer CC exams and keep the existing CS6 exams available while Adobe continues to sell and support our Creative Suite 6 product line. Creative Suite 5 exams will be retired as the new CC offerings are released.
    I know there are a lot of questions that will come up as our ACEs begin to work with CC and prep for the new certifications. To coordinate with the CC certifications, the exams will now be based on time periods. Meaning your certification will be valid for a pre-specific length of time and  will be required to recertify to maintain the CC product certifications. We will begin posting the specifics around the timeframes, policies, etc. in advance of the CC exam launches. Feel free to reach out to us at [email protected] with questions and comments.
    Thanks,
    Tiffany

  • How will the Google Image Search API being deprecated/discontinued affect Photoshop Touch?

    How will the Google Image Search API being deprecated/discontinued affect Photoshop Touch?
    Important: The Google Image Search API has been officially deprecated as of May 26, 2011. It will continue to work as per our deprecation policy, but the number of requests you may make per day may be limited.
    https://developers.google.com/image-search/

    Alternative options will be implemented as needed.
    -Dave

  • How will the new OSX Mavericks affect applications already installed and using Mountain Lion?

    How will the new OSX Mavericks affect applications already installed and using Mountain Lion?

    If you're asking about compatibility, that would be something you would need to ask of the app developers, though most apps compatible with Mountain Lion should be compatible with Mavericks. You can also consult the tables here:
    http://roaringapps.com/apps
    though that information comes from user reports and so should not be considered authoritative.
    If you're asking whether installing Mavericks will delete your apps, no, it won't, though a good backup is always highly recommended.
    Regards.

  • How will the preorder work?

    how will the preorder work?

    Yes.
    You can use the 3G as an iPod Touch - there is no device limit for the number of iPods, iPhones, and iPads that can be synced with the same iTunes library and iTunes account on the same computer.
    The iPhone 4 will use a micro-SIM card - just as with the iPad. Keep the no longer activated SIM card with your 3G inserted in the 3G even after the iPhone is no longer activated. In order to install a firmware update on a no longer activated iPhone or restore a no longer activated iPhone with iTunes if wanted or needed, the no longer activated SIM card needs to be inserted in the iPhone - the SIM card that was used with the iPhone when it was activated.
    You can enable Airplane mode followed by turning on wi-fi access when internet access is required.

  • How will the Time Capsule support IPv6 and coop with the new emerging security threats that will emerge due to the new technical possibilities that IPv6 provide?

    How will the Time Capsule support IPv6 and coop with the new emerging security threats that will emerge due to the new technical possibilities that IPv6 provide?

    Cross your fingers and hope.
    Obviously if there is any big or known threat Apple will send out a firmware fix.
    But the TC is designed to be end user simple device. It has no firewall that is visible at any rate. I don't know that it truly doesn't have a firewall but it is not part of the end user controls.
    IMO if you have major security concerns that go beyond end device firewall, which is where Apple do put most of the security, since firewall in the router is plainly not a stop to anybody deliberately downloading an infected file or website, and most end users.. do not want a firewall that prevents them using the web like a business does, where only certain ports are allowed. Everything else tough luck.. you are not allowed to use it. Then TC is unsuitable for you anyway.. buy a proper firewall appliance.

  • How will the itunes match app affect my data usage?

    how will the itunes match app affect my data usage? It seems to take a while to connect and start playing so i'm assuming if my range isnt the best it will drop out like a bad radio station???

    What I have done is create playlists and I'll download the playlists to the iPhone while I'm at home, on Wi Fi, and listen while I'm out and about. I've only downloaded the occasional tracks on 3G (mainly because at&t's network was so terrible). This method worked pretty well for me.
    Incidentally, iTunes Match should not be used as a substitute for a backup: FAQ:  Why iTunes Match can NOT be used as a backup!

  • HT4972 will the info in my apps (Passwords, notes and records) be saved when I update to iOS5

    will the info in my apps (Passwords, notes and records) be saved when I update to iOS5

    Yes, as long as you back up the iPod first via iTunes before performing the update.  Use the instructions in this Apple support document to walk you through the upgrade process.
    iOS: How to update your iPhone, iPad, or iPod touch
    B-rock

  • I bought this ipad 4 in canada.and it has hardware problems.how will i return this ipad when im not anymore in canada?

    How will i return this ipad if im not anymore in canada?it has hardware problem.pls help

    Send it to a friend or relative in Canada to take to Apple for service,
    and then that person can send back to you when Apple is done. You
    are responsible for shipping and insurance.
    Apple does not accept international shipments for service nor will
    Apple ship out of the country after service.
    If there is an Apple store or Apple authorized service provider where
    you are, try them - but be prepared for them to refuse since the iPad
    was not sold at your location.

  • How can I send a file that CAN NOT be printed or saved by the recipient?

    How can I send a file that CAN NOT be printed or saved by the recipient?

    Impossible. PDF files don't stream, so they cannot be opened until they've been saved.
    You can truly prevent printing by using DRM, or ask nicely by using a permissions password (though that's ignored by non-Adobe software).

  • I just upgraded my system to Mountain Lion. If I restore my Macbook Pro back to the very beginning state, will the Mountain Lion be removed or not? Thank you

    I just upgraded my system to Mountain Lion. If I restore my Macbook Pro back to the very beginning state, will the Mountain Lion be removed or not? Thank you

    The only problem that I forsee is that some have reported problems getting machine-specific builds of Lion via Internet Recovery. Not sure if it's working yet or not. But you could give it a shot, I suppose. Basically what you want to do is 'prepare your computer for resale' - just like it came out of the box. Kappy, a pretty wonderful and very knowledgeable man, has tip for that which I have copied and will paste below:
    Boot to the Recovery HD:
    Restart the computer and after the chime press and hold down the COMMAND and R keys until the menu screen appears. Alternatively, restart the computer and after the chime press and hold down the OPTION key until the boot manager screen appears. Select the Recovery HD and click on the downward pointing arrow button.
    Erase the hard drive:
        1.    Select Disk Utility from the main menu and click on the Continue button.
        2.    After DU loads select your startup volume (usually Macintosh HD) from the left side list. Click on the Erase tab in the DU main window.
        3.    Set the format type to Mac OS Extended (Journaled.) Click on the Erase button and wait until the process has completed.
        4.    Quit DU and return to the main menu.
    Reinstall Lion: Select Reinstall Lion and click on the Install button.
    Note: You will need an active Internet connection. I suggest using Ethernet if possible because it is three times faster than wireless.
    Good luck,
    Clinton

  • HT201441 How will the device get connected to the internet if it's locked and is wifi only?

    My daughter left her purse in a fitting room briefly and once she realized this, it was gone. In her purse was her iPad mini wifi only. I am curious how would the iPad get connected to the internet if it is locked? I have find my iPhone activated and since it is a iOS 7 device I put in lost mode and set it to display my phone # and a message for a reward. I am guessing it would have to be wiped clean somehow and re activated to be signed into to get hooked to the internet. Am I on the right track that once this is done and it gets connected to the internet the device will display this message? Any comments will help thank you.

    Thank you for your imput Winston. But how is the IPad going to connect when you physically have to put in the wifi password for the wifi? I guess the iPad would be able to access a unsecured wifi? I also read what I believe is conflicting with your statement about iOS 7 that you can send the remote erase and still be able to track? I havent done this yet I want to be certain that if I erase it remotely I can still track. Thanks again for your time.

  • How will the applet tag behave for users without Java?

    I am considering using an applet I have created as a splash screen for my website. But I am worried that by doing this I will loose all the visitors that don't have Java. Is there a way I can have the splash screen detect whether or not the user has Java? If so, is there a way I can have the splash screen automatically forward the non-java users to the main page? Maybe I could put something between the <applet></applet> tags?
    �Caleb�

    That doesn't help. Had you read my post more carefully you would have better understood what I wanted. In any case, I have already figured out how to automatically forward the non-Java users to the main page. The only thing I worry about now is about the people who's computers crash whenever they try to run a Java applet.
    �Caleb�

Maybe you are looking for

  • When i plug in my ipod to itunes it shows an advertsment that wont go away

    i plug in my ipod touch into the computer and when i click on MY IPOD it show an advertisment  for an iphone application. when i click NOT NOW the advertisement wont go away. it stays on itunes not allowing me to sync or do anything on itunes with it

  • Nothing works when i try to install adobe air. :(

    Whenever I install Adobe Air I always get this error. "An error occurred while installing Adobe AIR. Installation may not be allowed by your administrator. Please contact your administrator." I am the administrator and did the run as adminstrator opt

  • Upgrade from Elements 8 to 12

    I have successfully run Elements 8 for years and now am considering upgrading to 12, which I understand is materially different. If I download Upgrade 12 from your web site. can I install it directly or must I first uninstall 8?

  • Photo album & sub-folder issue

    Good evening. Just upgraded to iLife 09. All went well except iWeb. Post-upgrade I see all my image folders, organized by country (for example, India) with sub-folders branching off for each city visited. Problem: the India folder is missing the sub-

  • JSE 8 - Tutorials covering GUI development?

    The version 7 tutorial doesn't match up - is there any good tutorial documentation covering GUI development with JSE 8 ? thanks!