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.

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

    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

  • 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

  • Formatted Text Edit - Formatting icons not visible

    Hi,
    I  am using Formatted Text Edit in a view.
    The problem is that the formatting icons  (bold, italics etc.) are not rendered on the browser for a user with Arabic locale.Instead of the icons, I see a cross.
    This happens in IE, Mozilla as well as in Chrome.
    This is working fine with Spanish and French users.
    Any pointers to the solution shall be highly appreciated.
    TIA.
    Regards,
    Himanshu

    OSS message on BC-WD-UR.

  • Text field - format mask

    Hi!
    How can I achieve that tex field will have formated mask like AB12 12345 123 123 1234 (first 2 signs are character - only AB, then there is 17 numbers with space), so when I write in that text filed numbers like 123451231231234 I get AB12 12345 123 123 1234? I don't know if I must use regular expression or something else.
    I use apex 4.1
    Regards,
    drama9346

    You can do this using javascript like in this example:
    http://apex.oracle.com/pls/apex/f?p=31517:127
    However, your requirement is more complicated and will need more coding.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.apress.com/9781430235125
    http://apex.oracle.com/pls/apex/f?p=31517:1
    http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494
    -------------------------------------------------------------------

  • 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'));
    }

  • Field format setting

    Post Author: nonnon
    CA Forum: General
    A field in the report cannot display continuing. if my field have many rows of text,the whole text will be displayed at the 2nd page, and the first page is blank. Any setting to make my report's field displayed continuingly? i mean when the field at the first page is full, will continue to b displayed at 2nd page at teh same field.

    Post Author: mushi_it
    CA Forum: General
    hi nonnon,have u tried the field's format text or format object properties by right clicking that. in that just try by selecting Can grow option in the common tab.lets c what happens

  • 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 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

Maybe you are looking for

  • How do you install itunes on a secondary hard drive

    I need to move my iTunes library to a bigger hard drive. Is there a way to move it to another drive and still be able to play from it? It seems when I try to do this it just goes back to my cdrive.

  • How can I write a video play to support playing both 4:3 and 16:9 video

    I am using Adobe Flash Builder 4 and I want to write a video player to put in my web page. It should be able to play 4:3 or 16:9 videos. How can I adapt UI when display 4:3 or 16:9 videos? Do I have to convert all old 4:3 video to 16:9 video? If I wa

  • Firewire to USB 2.0 adapter

    We have a few computers whose firewire ports aren't working correctly. I'd still like to use an external firewire drive with them if I can find an adapter for firewire 400 to USB 2. Does anyone know of any? Thanks, Dan

  • A field in adobe

    Hello , In some forms we find in the title expression  : purchase order : and {..} represent the number of purchace order. if we open adobe livecycle we will found two field: 11- a text  which contain the text "purchase order and {..} "  which is vis

  • Adobe ifilter for sharepoint 2007 32 bit version 8.2 not working

    Wont read inside pdf documents , used to,  have worked with microsoft in trying to resolve this but even after following install document to a "t" it just doesnt work.