How to mask and format an input field at the same time?

Dear Experts,
I need to have an input field, which has the following behavior:
1. The input field accepts only number, i.e. characters other than number are ignored (not displayed on the text field).
2. The number is automatically formatted to ###,###,### as the user enter the number.
Example as the user enter 1-2-3-4-5-6-7, the sequence of number displayed in the text field is:
1
12
123
1,234
12,345
123,456
1,234,567
I have done the following:
import java.awt.*;
import javax.swing.*;
import java.text.*;
import javax.swing.text.*;
class FormattedTFDemo {
     NumberFormat cf;
     JLabel jlab;
     JFormattedTextField jftfSalary;
     JFormattedTextField jftfEmpID;
     JButton jbtnShow;
     public FormattedTFDemo() {
          JFrame jfrm = new JFrame("JFormattedTextField");
          jfrm.getContentPane().setLayout(new FlowLayout());
          jfrm.setSize(240, 270);
          jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          try {
               MaskFormatter mf = new MaskFormatter("###,###,###");
               jftfEmpID = new JFormattedTextField(mf);
          } catch (ParseException exc){
               System.out.println("Invalid Format");
               return;
          jftfEmpID.setColumns(15);
          cf = new DecimalFormat("###,###,###");
          jftfSalary = new JFormattedTextField(cf);
          jftfSalary.setColumns(15);
          jftfSalary.setValue(new Integer(7000));
          jfrm.getContentPane().add(new JLabel("First field"));
          jfrm.getContentPane().add(jftfEmpID);
          jfrm.getContentPane().add(new JLabel("Second field"));
          jfrm.getContentPane().add(jftfSalary);
          jfrm.setVisible(true);
     public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
               public void run() {
                    new FormattedTFDemo();
}The "First field" adopts no. 1 behavior, i.e. it does not allow any character other than numbers, but the "," are always displayed and the number displayed as I enter 1-2-3-4-5-6-7 are:
1 , ,
12 , ,
123, ,
123,4 ,
123,45 ,
123,456,
123,456,7
which is not according to behavior no. 2
The "Second field" displayed 1,234,567 only after the focus left the text field and not while typing. Moreover, characters other than number can still be displayed and only rejected after the focus left the text field.
I need a guide of what text field and what filter / format / mask I should use. Am I correct to use JFormattedTextField? Is the only way to accomplish this by using JTextField and create my own PlainDocument for the textfield, where
I rebuild the displayed output after each character is entered?
Thanks for any advice,
Patrick

So exactly what do you want the user to put in? and what do you want to see?
I need to have an input field, which has the following behavior:
1. The input field accepts only number, i.e. characters other than number are ignored (not displayed on the text field).
2. The number is automatically formatted to ###,###,### as the user enter the number.
Example as the user enter 1-2-3-4-5-6-7, the sequence of number displayed in the text field is:
1
12
123
1,234
12,345
123,456
1,234,567The user should type only numbers and when he types other than numbers, the field ignore it.
What I want to see, as the user, for example, types 1-2-3-4-5-t-6-7 is:
1
12
123
1,234
12,345
<beep / ignore> (because t is invalid)
123,456
1,234,567
Thus, I need a guide of what swing components should I use to accomplish this task. If you can give me the code, that will be perfect.
Hope you can advise me,
Patrick

Similar Messages

  • How to add and remove storage from ASM at the same time?

    Scenario:
    I want to drop some disks from asm
    1- Add disk to asm -----> rebalance
    2- drop disk from asm ----> rebalance
    Is there anyway to make this process faster instead of going to rebalancing twice?

    I think you could try something like this.....
    Add with a power limit of zero and then drop the disks with a powerlimit of 11.
    alter system set ASM_POWER_LIMIT=0;
    select * from v$asm_operation;
    alter diskgroup DBFILE01_GRP
    add disk 'ORCL:DB0009', 'ORCL:DB0010', 'ORCL:DB0011', 'ORCL:DB0012';
    alter diskgroup DBFILE01_GRP drop disk DB0001, DB0002, DB0003, DB0004;
    alter diskgroup DBFILE01_GRP rebalance power 11;
    select * from v$asm_operation;

  • I was backing up my iPhone and importing photos onto iPhoto at the same time , then suddenly it says no more space available (i had 48GB before i do this and now i have 18GB) i can't find the back up or the photo anywhere , how can i delete them ?

    i was backing up my iPhone and importing photos onto iPhoto at the same time , then suddenly it says no more space available (i had 48GB before i do this and now i have 18GB) i can't find the back up or the photo anywhere , how can i delete them ? i dont need the pictures or the back ups , i want to delete them but they are not there

    Empty the Trash if you haven't already done so. If you use iPhoto, empty its internal Trash first:
    iPhoto ▹ Empty Trash
    Do the same in other applications, such as Aperture, that have an internal Trash feature. Then reboot. That will temporarily free up some space.
    According to Apple documentation, you need at least 9 GB of available space on the startup volume (as shown in the Finder Info window) for normal operation. You also need enough space left over to allow for growth of the data. There is little or no performance advantage to having more available space than the minimum Apple recommends. Available storage space that you'll never use is wasted space.
    When Time Machine backs up a portable Mac, some of the free space will be used to make local snapshots, which are backup copies of recently deleted files. The space occupied by local snapshots is reported as available by the Finder, and should be considered as such. In the Storage display of System Information, local snapshots are shown asBackups. The snapshots are automatically deleted when they expire or when free space falls below a certain level. You ordinarily don't need to, and should not, delete local snapshots yourself. If you followed bad advice to disable local snapshots by running a shell command, you may have ended up with a lot of data in the Other category. Reboot and it should go away.
    See this support article for some simple ways to free up storage space.
    You can more effectively use a tool such as OmniDiskSweeper (ODS) to explore the volume and find out what's taking up the space. You can also delete files with it, but don't do that unless you're sure that you know what you're deleting and that all data is safely backed up. That means you have multiple backups, not just one.
    Deleting files inside an iPhoto or Aperture library will corrupt the library. Any changes to a photo library must be made from within the application that created it. The same goes for Mail files.
    Proceed further only if the problem isn't solved by the above steps.
    ODS can't see the whole filesystem when you run it just by double-clicking; it only sees files that you have permission to read. To see everything, you have to run it as root.
    Back up all data now.
    If you have more than one user account, make sure you're logged in as an administrator. The administrator account is the one that was created automatically when you first set up the computer.
    Install ODS in the Applications folder as usual. Quit it if it's running.
    Triple-click anywhere in the line of text below on this page to select it, then copy the selected text to the Clipboard by pressing the key combination command-C:
    sudo /Applications/OmniDiskSweeper.app/Contents/MacOS/OmniDiskSweeper
    Launch the built-in Terminal application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Terminal in the icon grid.
    Paste into the Terminal window (command-V). You'll be prompted for your login password, which won't be displayed when you type it. You may get a one-time warning to be careful. If you see a message that your username "is not in the sudoers file," then you're not logged in as an administrator.
    The application window will open, eventually showing all files in all folders, sorted by size with the largest at the top. It may take a few minutes for ODS to finish scanning.
    I don't recommend that you make a habit of doing this. Don't delete anything while running ODS as root. If something needs to be deleted, make sure you know what it is and how it got there, and then delete it by other, safer, means. When in doubt, leave it alone or ask for guidance.
    When you're done with ODS, quit it and also quit Terminal.

  • Help - Need Line in and Aux inputs active at the same time..... Audigy SE

    The company I work for purchased 3,000 of the Audigy SE? SB0570 sound cards to replace our aging original SB6 PCI cards used in our call centers. The application and Hardware require that the AUX connector and the Line in connector are both acti've at the same time in order for things to work properly.
    Problem is that when I go into the mixer settings (or windows volume controls) when I select one of the inputs to go acti've, it mutes the other two inputs (mic, line-in, or AUX). Does anyone know of a work around to let me activate the AUX and/or Line-in/Mic at the same time??
    Our workstations run Windows 2000? (but as a test, I?loaded up another PC with XP SP2 and it exibits the same problems)
    Thanks in advance for your help.

    We are using the internal AUX in connector to take audio from a vendors custom card, and at the same time we have to take audio in on the flexi-jack input on the rear of the card. The original SB PCI cards we have been using for 5 years allowed us to do this, but these new ones do not. I wrote an e-mail to Creative Tech support and here is their response: Basically it is a no go, so I am now looking at other manufactures that can support our requirements. Good news is that I contacted our supplier today and they are willing to take back all of the cards that are still sealed in their original packaging... about 2,800 of them.
    Dear Harry
    Thank you for reaching us at Creative Email Technical Support; we appreciate the opportunity to assist you.
    Based on your description, I understand that you are unable to use AUX IN and Line In/Mic In simultaneously.
    I would like to apologize for any inconvenience and seek your understanding, and are certainly thankful that you have taken precious time to bring this matter to our attention.
    Please allow me to assist you with regard to this issue.
    For your information, you are only able to use one of the option at a time.
    If you are trying to do a Recording, you may select "What U Hear"
    option.
    I hope the above mentioned solutions will be able to resolve your issue.
    If you still require assistance, please reply to this email with any previous correspondence to ensure the quickest and most accurate service.
    Best Regards,
    *removed*
    Technical Support
    Creative Labs Americas
    To provide feedback on your "Creative Experience" please click on the following link:
    http://www.**bleep**.com/support/contact/welcome.asp?r=CLI&d=TS[/u]
    This link is provided so that you may provide feedback on your "Creative Experience". If you require further troubleshooting or have additional questions simply reply to the original mail and we will be glad to assist you.
    Admin notes: Removed the name of the support advisor for their privacy.
    Message Edited by KokChoy-CL on <span class='local-date'> 0-22-2009<span class='local-time'> 0:57 [email protected]

  • I am doing two people's jobs and I need to use two separate log-ins on the same website. How can I keep both log-ins open at the same time. Everytime I switch tabs I have to log in again.

    I am doing two people's jobs and I need to use two separate log-ins on the same website. How can I keep both log-ins open at the same time. Everytime I switch tabs I have to log in again.

    Try one of these extensions for multiple cookie sessions.
    Multifox: <br />
    http://br.mozdev.org/multifox/ <br />
    Cookie Swap extension: <br />
    https://addons.mozilla.org/firefox/3255/ <br />
    Cookie Pie extension: <br />
    http://www.nektra.com/oss/firefox/extensions/cookiepie/

  • Phone and my husbands iphone ring at the same time when only one of us is being called. How can I stop this from happening?

    Both my iphone and my husbands iphone ring at the same time when only one of us is being called. How can I stop this from happening?

    This post has already been answered. Why are you plugging your own site with an answer that has already been given? Not to mention that the information you are handing out is incorrect. There is no bug, there is no patch, and no one needs to delete any email addresses. If you take the time to read the posts with the correct answers, you will see that the solution is totally different than the erroneous one you have posted.
    GB

  • Can anybody explain how to print multiple copies of different documents at the same time as at the moment I have to open each individually and press print

    Can anybody explain how to print multiple copies of different documents at the same time as at the moment I have to open each individually and press print

    is this a windows in bootcamp question ?

  • How to play stereo mix music and sing in my mic at the same time?

    Hi guys, need help regarding Realtek HD audio driver
    I want to play stereo mix music and sing in my mic at the same time.... not for recording purposes but in chatroom let's say.
    I'm using XP...Toshiba Satellite S4747 laptop
    In the Realtek software under " Realtek HD audio input" I have mic and stereo mix both.... but I can only select one at a time.....
    Any solutions plzzz thxxxx
    On a different note.... a friend of mine whose using one non-Toshiba laptop with win XP has an older version of the Realtek audio driver and can select both mic and stereo mix at the same time... I downloaded that version into my laptop but I still can only select one at a time....

    Check the audio settings in Windows and dont forget in Realtek HD audio manager. You can find it in control panel.
    I think your microphone is set to mute so check this.

  • Yesterday, I downloaded I.O.S. 8 to both my iPhone and my wife's iPad at the same time.  She wants I.O.S. 8 removed.  How do I remove it from both devices?  I am willing to resort to my old IOS7.1.2.

    Yesterday, I downloaded I.O.S. 8 to both my iPhone and my wife's iPad at the same time.  She wants I.O.S. 8 removed.  How do I remove it from both devices?  I am willing to resort to my old IOS7.1.2.

    Sorry...downgrading is not supported.

  • HT204368 How do I connect more than one Bluetooth enabled music device (subwoofer and Jambox) to my iPad at the same time?

    How do I connect more than one Bluetooth enabled music player (subwoofer and Jambox) to my iPad at the same time?

    You could start by posting onto an iPod forum instead of a "Using iPad" forum.  

  • How can I get rid of multiple pictures at the same time?

    how can I get rid of multiple pictures at the same time?

    Adobe Bridge, lightroom and your file browser (windows explorer or Mac Finder) can select multiple pictures at once and then delete. If you are looking for more than that for information, you will need to be more specific at what your doing, what OS you have, and version of software your using. If necessary post screen shots so we can see what your doing. The more information we have the more detailed of an explaination can can give back to you.

  • How do i open 2 hotmail outlook accounts at the same time? Thanks.

    How do I open 2 hotmail outlook accounts at the same time? Thanks.

    Safari only lets me to sign in to one hotmail account at any one time. If I am signed in to one account and I open a new window (or tab) the existing hotmail account I am signed in to opens again (I want to sign into second account simultaneously). So I am trying to sign in to 2 hotmail accounts at the same time. Does that makes sense?

  • How do I get 2 layers to move at the same time?

    How do you get 2 layers to move at the same time?

    Thanks for the help folks, sorry I've been away.
    I'd love help with the problem of why I only one track seems to accept clips to play. When I drag them to other tracks or create a track by dragging the clips are grayed out and won't play, but if I drag them to the one track where they're blue they play.

  • It is possible to charge an iPad3 over USB and transmit data over USB at the same time?

    Hello,
    it is possible to charge an iPad3 over USB and transmit data over USB at the same time?
    If yes, how?
    Thanks
    Best regards

    OK!?
    That is right that the USB data oins are not connected to +5V pin.
    But i found a description for a self built power supply for iPad.
    http://timothyb.net/DIY_iPad_2_USB_Charger.html
    and
    https://www.mikrocontroller.net/topic/262610?goto=2726627#2726627
    The description say: data pin D- need a voltage level of 2V and D+ 2,857V
    when the data pins have this special voltage levels and VCC has +5V only then the iPad is charging.
    The voltage "D+/D- coding" is the key for the iPad to charge.
    OK now back to my problem.
    The regular USB data pin voltage level is 0,3 - 3.,0 voltage. When the iPad is charging the data pins have this special voltage level. Now i try to transmit data over the usb data pins with the. Normaly the USB port transmit the data with a voltage level of max. 3V.
    And here my problem. The higher voltage level at the data pins cares therefor that the iPad stop the charging.
    Is that correct?

  • SCXI 1112 and 1302 doesn't run at the same time

    Hi,
    I have SCXI 1112 thermocouple input module,  SCXI 1180 feedthrough panel , and a SCXI 1302 terminal block connected SCXI 1000 chassis with SCXI 1349 adapter. I am trying to measure voltage by using SCXI 1180&1302, and temperature by 1112 module at the same time. When  chassis is on SCXI 1112 runs without a problem; however, voltage reading coming through SCXI 1349 makes no sense (plus I can't run them at the same time, LAbview gives an error). While the chassis' power is off, it is the other way around, SCXI 1349 runs smoothly.
    In addition to that, a radiometer, connected to a power supply, is wired to SCXI 1302 terminal block. When power supply is on, SCXI 1112 module's temperature reading is 4 times higher than actual value. In other words, power supply effects the readings.
    Could you please give me some advice to solve this problem?
    Thanks,
    Azra

    One piece of the puzzle you left out is the DAQ card being used in the host computer. 
    Without looking at some specifics on the SCXI cards/connectors you are using, I will comment you must be careful when you are using an 1180 feedthrough module.  Keep in mind, the SCXI chassis is Signal Conditioning -- it's nothing without the DAQ. 
    I would recommend you back up a few steps, simplify the setup and test each input channel from MAX -- making sure you aren't overlapping channels between the 1180 to the DAQ and the SCXI chassis.  Remember, most data from the SCXI chassis comes in on a single channel of the DAQ through the 1349.
    Hope this might help. 
    RS

Maybe you are looking for

  • Question about MP affinity in a multi-forest scenario without AD publishing

    I am looking at deploying an SCCM system that will feature multiple forests and the caveat of NOT being able to use any sort of AD publishing or schema extension. Knowing this, and that clients will use the MP residing in their forest by default... W

  • Project-wise cash Flow

    Respected Guru's,                              There is a requirement of project wise Cost flow here. So, Please suggest what are the attributes needed to get on the same? And, what are the reports needed to analyze upon? Any documentary will be of g

  • Tracing Changes in Material Data

    Hi, How can you trace changes in a material given that the only data you have is the previous value? For example, I have changed the EAN/UPC number of a material from 4800000000001 to 480000000002. Now, the only data I have is the EAN 480000000001 (n

  • MAC Itunes Mp3 CD Problem

    Please Help I need to burn an Mp3 cd on my mac. I need some of the songs to play 3 or 4 times, so I cannot use toast unless i change each song names 3 times So I tried using Itunes Playlist. But none of the 2 equipments I use can read the Cd's burned

  • Output value in adobe form is / are empty

    Hey gurus, I need to solve following issue: User creates an activity = task in CRM and wants to create a PDF with the task details an save it in attachments of the task I need to generate a simple adobe form and not an interactive form my steps: 1) I