Formatted Text Field

I have a text field that I want the user to be able to enter up to 4 numbers. I tried a mask formatter using the "####" format, but that forces the user to enter 4 numbers. I want them to be able to enter, 1,2,3 or 4 numbers.

Hi,
I've implemented number fields based on JFormattedTextField.
They also support a min and a max value.
Maybe you find them useful (the library is open source):
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JRealNumberField.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JDoubleField.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JFloatField.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JLocalizedRealNumberField.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JLocalizedDoubleField.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JLocalizedFloatField.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JWholeNumberField.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JByteField.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JIntegerField.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JLongField.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JShortField.html
Tutorial:
http://softsmithy.sourceforge.net/lib/docs/tutorial/swing/number/index.html
Homepage:
http://www.softsmithy.org
Download:
http://sourceforge.net/project/showfiles.php?group_id=64833
Source:
http://sourceforge.net/svn/?group_id=64833
http://softsmithy.svn.sourceforge.net/viewvc/softsmithy/trunk/lib/src/org/softsmithy/lib/
-Puce

Similar Messages

  • How to create Using Formatted Text Field with multiple Sliders?

    Hi i found the Java Sun tutorial at http://java.sun.com/docs/books/tutorial/uiswing/components/slider.html very useful, and it tells how to create one Formatted Text Field with a Slider - however i need to create Formatted Text Field for multiple Sliders in one GUI, how do i do this?
    my code now is as follows, and the way it is now is scroll first slider is okay but scrolling second slider also changes value of text field of first slider! homework due tomorrow, please kindly help!
    // constructor
    label1 = new JLabel( "Individuals" );
    scroller1 = new JSlider( SwingConstants.HORIZONTAL,     0, 100, 10 );
    scroller1.setMajorTickSpacing( 10 );
    scroller1.setMinorTickSpacing( 1 );
    scroller1.setPaintTicks( true );
    scroller1.setPaintLabels( true );
    scroller1.addChangeListener(this);
    java.text.NumberFormat numberFormat = java.text.NumberFormat.getIntegerInstance();
    NumberFormatter formatter = new NumberFormatter(numberFormat);
            formatter.setMinimum(new Integer(0));
            formatter.setMaximum(new Integer(100));
    textField1 = new JFormattedTextField(formatter);
    textField1.setValue(new Integer(10)); //FPS_INIT
    textField1.setColumns(1); //get some space
    textField1.addPropertyChangeListener(this);
    //React when the user presses Enter.
    textField1.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),  "check");
            textField1.getActionMap().put("check", new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    if (!textField1.isEditValid()) { //The text is invalid.
                        Toolkit.getDefaultToolkit().beep();
                        textField1.selectAll();
                    } else try {                    //The text is valid,
                        textField1.commitEdit();     //so use it.
                    } catch (java.text.ParseException exc) { }
    label2 = new JLabel( "Precision" );
    scroller2 = new JSlider( SwingConstants.HORIZONTAL, 0, 100, 8 );
    scroller2.setMajorTickSpacing( 10 );
    scroller2.setMinorTickSpacing( 1 );
    scroller2.setPaintTicks( true );
    scroller2.setPaintLabels( true );
    scroller2.addChangeListener(this);
    textField2 = new JFormattedTextField(formatter);
    textField2.setValue(new Integer(10)); //FPS_INIT
    textField2.setColumns(1); //get some space
    textField2.addPropertyChangeListener(this);
    //React when the user presses Enter.
    textField2.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),  "check");
            textField2.getActionMap().put("check", new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    if (!textField2.isEditValid()) { //The text is invalid.
                        Toolkit.getDefaultToolkit().beep();
                        textField2.selectAll();
                    } else try {                    //The text is valid,
                        textField2.commitEdit();     //so use it.
                    } catch (java.text.ParseException exc) { }
    // State Changed
         public void stateChanged(ChangeEvent e) {
             JSlider source = (JSlider)e.getSource();
             int fps = (int)source.getValue();
             if (!source.getValueIsAdjusting()) { //done adjusting
                  if(source==scroller1)   {
                       System.out.println("source ==scoller1\n");
                       textField1.setValue(new Integer(fps)); //update ftf value
                  else if(source==scroller2)     {
                       System.out.println("source ==scoller2\n");
                       textField2.setValue(new Integer(fps)); //update ftf value
             } else { //value is adjusting; just set the text
                 if(source==scroller1)     textField1.setText(String.valueOf(fps));
                 else if(source==scroller2)     textField2.setText(String.valueOf(fps));
    // Property Change
        public void propertyChange(PropertyChangeEvent e) {
            if ("value".equals(e.getPropertyName())) {
                Number value = (Number)e.getNewValue();
                if (scroller1 != null && value != null) {
                    scroller1.setValue(value.intValue());
                 else if (scroller2 != null && value != null) {
                    scroller2.setValue(value.intValue());
        // ACTION PERFORMED
        public void actionPerformed(ActionEvent event) {
        if (!textField1.isEditValid()) { //The text is invalid.
            Toolkit.getDefaultToolkit().beep();
            textField1.selectAll();
        } else try {                    //The text is valid,
            textField1.commitEdit();     //so use it.
        } catch (java.text.ParseException exc) { }
             if (!textField2.isEditValid()) { //The text is invalid.
            Toolkit.getDefaultToolkit().beep();
            textField2.selectAll();
        } else try {                    //The text is valid,
            textField2.commitEdit();     //so use it.
        } catch (java.text.ParseException exc) { }
    ...

    if :p3_note_id is null
    then
    insert into notes (project_id, note, notes_month, notes_year) So, p3_note_id is NULL.
    Another option is that you have a trigger on table NOTES that generates a new note_id even for an update.

  • Formatted Text field for File Extensions

    Hi guys,
    Is it possible to create formatted text field for file extension like it should accept *.bmp, .bmp, bmp. etc..... It is not necssary to be a Combo Box. TextField will work.
    Thanks in advance.
    AZGHAR

    Any one here \Help\Help\Help ;-(

  • Formatted Text Field for getting Date

    I need a text field to get Date. does anyone know where I can find such a thing?
    all it needs to do is allow the user to type a date in dd/MM/yy format.
    10x.

    in a jtable it has a problem - when I press tab to exit the field the date is not changed.
    i set the on focus lost behaviour to commit, but still not working.
    also, it allows me to enter 4823749823/02/02 - and it translates it to the right format - I'm interested in something more fixed - allows to enter only 2 digits for day, 2 digits for month,2 digits for year.
    the relevent code I'm using is:
    // a cellEditor that uses a formatted text field that holds a Date object
    public class JFormattedDateCellEditor extends DefaultCellEditor {
    public JFormattedDateCellEditor(final JFormattedTextField textField) {
    super(textField);
    textField.setFocusLostBehavior(JFormattedTextField.COMMIT);
    textField.setHorizontalAlignment(SwingConstants.RIGHT);
    textField.setFont(JUtility.theFont);
    textField.setBorder(null);
    textField.addFocusListener(new FocusAdapter() {
    public void focusLost(FocusEvent e) {
    if (textField.getValue() == null) {
    textField.requestFocus();
    delegate = new EditorDelegate() {
    public void setValue(Object value) {
    textField.setValue((java.util.Date)value);
    public Object getCellEditorValue() {
    return textField.getValue();
    //to set the cell editor:
    column = collectionsTable.getColumnModel().getColumn(CollectionFrame_collectionsModel.DATE_COLUMN);
    column.setCellEditor(
    new JFormattedDateCellEditor(
    new JFormattedTextField(
    new DateFormatter(
    new SimpleDateFormat("dd/MM/yy")))));

  • Need help formatting text field default value

    Hello,
    I've received a customer request to put default text into the Value section of a text field. They're requesting that the default text include line breaks, bullets, etc. I added a Text Field object and added the default text to the Object tab > Value tab Default field but can't figure out how to add line breaks, etc.
    Thanks in advance,
    Saskia

    Hi,
    this is possible but not doable with the UI of Designer.
    The workaround is as follows:
    1. Create a text, enter your default text with all the formattings you need (text color, bold text, line breaks etc.)
    2. Create a text field and enter any word as default value. Let's say "Default".
    3. Select the text and the switch to the XML Source view.
    There you will find all the formatted text between the <value> tags such as:
    <value>
         <exData contentType="text/html">
              <body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"><p style="letter-spacing:0in">This is<span style="xfa-spacerun:yes"> </span></p><p style="color:#ff0000;letter-spacing:0in">default Text</p><p style="letter-spacing:0in"><span style="xfa-spacerun:yes"> </span>• with<span style="xfa-spacerun:yes"> </span><span style="font-weight:bold">RichText</span> formatting.</p></body>
         </exData>
    </value>
    4. Select the whole code between the <value> tags and copy it to the clipboard (ctrl + c).
    5. Go to the Design View, select the text field, go back to the XML Source view.
    6. There you'll also find the value <tags> and your default value you entered before.
    <value>
         <text>Default</text>
    </value>
    7. Select this code section and paste the value copied before to the clipboard by pressing ctrl + v.
    8. That's it. When you now go back to the Design View your text field shows a formatted RichText as defaul text.

  • Formatted Text Field Formats

    I have a FormattedTextField where the user inputs a decimal value. It works just fine, until the user deselects the field. At this point, if the value is <1 with three leading zeros (i.e. 0.0001), the field displays 0. The correct value is obtained from the text field, and it displays just fine when it's being edited, but the output is inaccurate.
    // I print via String valueOf to make sure the issue isn't at a String function, and it turns out okay
    console.printConsole(String.valueOf(a3));
    // I specify a formatter factory with my own object (defined below)
    // Since I use the same formatter object for the display, input, edit params, I would
    // think the way it is outputted wouldn't change across these, but it does
    label3 = new JLabel("i power " + 3 + " coefficient");
    field3 = new JFormattedTextField(new DefaultFormatterFactory(
    new CalFormatter(),
    new CalFormatter(),
    new CalFormatter()));
    // And I make sure there are enough columns to display the info
    field3.setValue(new Double(a3));
    field3.setColumns(10);
    // My cal formatter object
    class CalFormatter extends NumberFormatter{
    public CalFormatter(){
    super();
    // I manually call the valueOf String function in case that's where the loss of accuracy originates
    // ...no luck
    public String valueToString(double number) throws ParseException {
    return String.valueOf(number);

    what happens when you switch the lines to do the following:
    from this:
    field3.setValue(new Double(a3));
    field3.setColumns(10);
    to this:
    field3.setColumns(10);
    field3.setValue(new Double(a3));
    setColumns clears the field, so that may be your problem.

  • SelectAll() on a (custom) formatted text field

    Hi everybody,
    I have a JFormattedTextField to which I have set two separate formatters one for edit and one for display.
    I would like to selectAll() the text in the field anytime the field get the input focus.
    I tried to set a foculistener, but did not work. I found in the forum I should not use the focuslistener, rather a requestFocus() + selectAll() but I don't know when to call the requestFocus...
    Thanks in advance for your replies.

    I hope you understand why "it worked fine". SwingUtilities.invokeLater is a cover method for EventQueue.invokeLater -- it places the execution of the Runnable's run method at the end of the queue.
    Without that construct, your selectAll was cutting ahead of events already in the queue -- one of which was the actual transfer of focus to the text field, which by default (as you know) removes any pre-existing selection.
    With the invokeLater, selectAll is placed at the end of the queue, and is invoked after the text field has already gained focus.
    db

  • Formatting Text field in Adobe Forms

    Hi guys,
    I'm trying to print text with a bigger font size, but it doesn't work... I always got the same result when printing.
    I'm changing the font size in the Font palette, but no changes.
    Could you please help me?
    Regards,
    David

    Hi David,
    Looks like a Product issue. Refer to following SAP notes. 
    2058683 - IFbA: Font mapping for PDF preview in spool
    You use SAP Interactive Forms by Adobe. PDF preview in spool management does not take font mapping into account.
    1489570 - Set font mapping for PDF forms
    Reward points if helpful.
    Regards
    Sandy

  • I want to create decimal number formated text field

    hi
    I am trying to create decimal for eg 1234.20
    only this type number can acssess
    for that what I do

    try adding a CustomKeyListener to your text component....
    to create decimal for eg 1234.20((JTextComponent)component).addKeyListener(CustomKeyListener(4,2));
    import java.awt.event.*;
    import javax.swing.text.JTextComponent;
    public class CustomKeyListener extends KeyAdapter {
         char separator = '.';
         // total digits allowed
         int maximumSize ;
         // digits before the separator
         int before = -1;
         // digits after the separator
         int after = -1;
         public CustomKeyListener(int the_before,int the_after) {
              before = the_before;
              after = the_after;
              maximumSize = before+after+1;
         public void keyTyped(KeyEvent e){
              JTextComponent txtComp = (JTextComponent) e.getSource();
              if (txtComp.getText().length() < maximumSize ){
                   if(Character.isDigit(e.getKeyChar())||
                             e.getKeyCode() == KeyEvent.VK_BACK_SPACE||
                             e.getKeyChar() == separator ||
                             e.getKeyChar() == ',') {
                   // if txtComp contains a separator
                        if (txtComp.getText().indexOf(",") != -1 ||
                             txtComp.getText().indexOf(".") != -1     ){
                   // a second separator (if typed) will be deleted
                                  if (e.getKeyChar() == separator ||
                                                 e.getKeyChar() == ',')     {
                                  e.setKeyChar(new Character('\b'));
                                  return;
                   // typed a digit
                             int separatorPosition;     
                             if (txtComp.getText().indexOf(",") != -1 ){                         
                                  separatorPosition =txtComp.getText().indexOf(",");
                             else{                         
                                  separatorPosition =txtComp.getText().indexOf(".");
                             // finding caret position
                             int cp = txtComp.getCaretPosition();
    //                         System.out.println("posizione del caret " + cp);
                   // caret before separator
                             if ( cp <= separatorPosition ){
                                  if (txtComp.getText().
                                            substring(0,separatorPosition).trim().length()<
                                            before){     
                                       return;
                                  else{                              
                                       e.setKeyChar(new Character('\b'));
                                       return;          
                             else{
                             // caret after separator
                                  if (txtComp.getText().
                                            substring(separatorPosition+1).length()<
                                            after){     
                                       // digit is ok!
                                       return;
                                  else{
                                       e.setKeyChar(new Character('\b'));
                                       return;
                        else{
                        // separator absent
                             // if is typed a separator
                             if (e.getKeyChar() == separator ||
                             e.getKeyChar() == ','){
                                  int cp = txtComp.getCaretPosition();
                                  if (txtComp.getText().length() - cp-1 < after){
                                       return;
                                  else{
                                       e.setKeyChar(new Character('\b'));
                                       return;
                             // is typed a digit
                             else{                              
                                  if(txtComp.getText().trim().length()<before){
                                       return;
                                  else{
                                       e.setKeyChar(new Character('\b'));
                                       return;
                   }else{
                        // the key pressed isnt numeric
                        if (Character.getNumericValue(e.getKeyChar())!=-1)
                        e.setKeyChar(new Character('\b'));
                        return;
              else{
                   // Maximum lenght reached
                   e.setKeyChar(new Character('\b'));
    }

  • How can I place a text field not directly on the left of the page but with an indent to the right?

    Hi everybody,
    I try to create a form in which I want to enter several item under each other
    general info        Item 1               Item 2
                             Name 1            Name 2
                            Item 3               Item 4
    and so on.
    Since it is not possible to insert a table for something like that I would like to enter seperate text fields one underneath the other.
    But every new line starts on the left side and I do not see any way to move a text field to the right with an indent so that "item 1", "Name 1" and "item 3" are aligned the same.
    Can anybody give me a hint?
    Thanks a lot and have a good 2015!
    Oliver

    Hi,
    Insert a blank "Formatted Text" field on the far left, and shrink it down as much as you wish. Then insert your normal text field to the right of that.
    I hope that helps,
    Brian

  • How can I add some help text to a plain text field?

    I would like to put the basics in the plain text (formatted text) field and then some details and clarifications in the help text area.  Seems like this would be easy and useful.

    Thanks for your feedback. I don't think we ever thought of using the help text that way.
    Randy

  • Rich Text Field in HTML

    I need to design an xdp form that can be rendered in HTML and which allows the user to format text field content. I created a text field control with data format of xhtml. In Adobe Acrobat Professional I can use CNTRL-E to open the "Form Field Text Properties" toolbar. Will this work in the web browser when the form is rendered as HTML?
    Also, is it possible to insert a hyperlink into a rich text field when rendered as HTML or PDF? Are hyperlinks even supported in text fields of forms designed using LiveCycle?

    hi
    another way to do it is to specify RenderFormat property of Content by search web part (it is not available from UI, only programmatically or declaratively):
    <property name="RenderFormat" type="string">&lt;Format Type=&quot;HTML&quot; /&gt;</property>
    Format is very important and it should be exactly like shown above. Check the following post for details:
    Problem with trimmed html content in search index in Sharepoint 2013.
    Blog - http://sadomovalex.blogspot.com
    Dynamic CAML queries via C# - http://camlex.codeplex.com

  • Complex formated Text from Databse to textmember

    Hello Forum,
    I try to save a complex rtf formated text field into a field
    of a database, called Valentina. But after writing the text back to
    the text field, all formatings of the text are overwritten. So I
    tried to save the rft-format sequences to the databease, too. But
    now they appear in the text field, too. Is it basically possible to
    save the text with all his attributes into the database and write
    it back to the text field?
    Best regards
    Alexander

    Hello Udo,
    thanks a lot for your help. I tested it yesterday evening
    first without Valentina. It works fine. The main problem was that I
    mixed .rtf with .text or .value, too. So the rft format appeared in
    the text member. My last programming jobs with director is about
    seven years ago, except the small part, two years ago. My next step
    will be the test with Valentina.
    Best regards from Fulda
    Alexander

  • How to provide text formatting options to user from a text field

    Hi,
    My requirement is - in the interactive form, a comments field needs to be provided where user should be able to enter text with formatting options like
    Headers
    indentations
    bold/italic
    bullet points and numbers
    Once user enters the formatted texts in a text field, data needs to be displayed/printed in the same format. Could you help me on how to provide these formatting options to the user for a particular text field?
    I understand that once I define the text field with format XHTML (with RTF), user formatting can be captured and displayed in the same way. But I am not sure on how to provide the formatting options for the text field.
    Thank you,
    Madhu

    Hi,
    if you select a text field for Rich Text and the press Ctrl + E you'll get a bar for all available text formatting options in Acrobat/Reader.

  • How to create a group/list of check box variables for display in text field, in appended format

    I need to identify a series of single-response checkbox variables and display the ones selected (as a group) in a text field in an appended (comma, space) format. Last week, you provided a great little script for a similar need using List Box (multiple response) variables. This time I need to know how to formally identify the checkbox variables and, I presume, use a similar script to display the results in a comma, space format.
    You've been of great help.
    Thanks

    Here's the script adapted to this situation. It assumes there are ten check boxes named cb1, cb1, cb2, ...cb10.
    // Custom Calculate script for text field
    (function () {
        // Initialize the string
        var v, s = "";
        // Loop through the check boxes to build up a string
        for (var i = 1; i < 11; i++) {
            // Get the value of the current check box
            v = getField("cb" + i).value;
            if (v !== "Off") {
                if (s) s += ", ";  // Add a comma and a space if needed
                s += v;  // Add the selected value
        // Set this field value to the string
        event.value = s;
    You'll have to change the field name and starting/ending numbers to match your form.

Maybe you are looking for

  • Consumption Report

    Hi Expert, I want to make a consumption stock report date wise.User will put material type,material code,and date what table and field should i take for making this report. Pl z help............

  • Recovering deleted emails from blackberry

    I accidently deleted some important emails from my "mailbox & handheld" by accident. Is there anywhere in the handheld to retrieve the deleted messages?

  • Can't open Adobe Reader XI! May not have appropriate permissions?? Need help!

    Here's the deal. I noticed I wasn't able to open up my PDF files like I used to (it would suddenly pop up a window asking if I wanted to open the file using another program on my computer or the web) so I figured that the latest update might've done

  • KM content Migration from EP 5 to Ep7

    Hi There. We are trying to migrate Km content from EP5 to EP.. i know that this can be achieved through ICE. and i have seen couple of blogs also but i am still not able to get any step by step info..  along with all pre-requisite.. Can you please sh

  • Policy-Map

    Ok I am going insane here! I have a policy map on one of my 5k's but not the other and seem to create it either. They are in an active/active pair. Here is the policy, can someone help me understand what it is and maybe why I cant create it on my oth