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

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.

  • Customer Master Text Fields

    Hello,
    What tables and relations would be used to access the customer master sales data short and long text fields in an SQ01 query?
    Thanks for your reply.

    Hi,
    I think KNVV would be the starting table and the text tables would be related to KNVV. When doing an F1 on the short and long text fields I get RTEXT-TTEXT and RTEXT-LTEXT but these can't be used in an SQ01 query.
    Regards

  • Custom Webdynpro text field is taking too long to accept input values

    Dear All,
                   I hvae created custom web dynpro for PO header fields in SRM. This WD contains a lot of fields. When i try to put cursor on a text field it is taking too long for the cursor to appear in that input text field. There is no problem with other fields which have search helps associated with them. This field with the problem is just a text field.
    Please help.
    thanks.

    Dear All,
                   I hvae created custom web dynpro for PO header fields in SRM. This WD contains a lot of fields. When i try to put cursor on a text field it is taking too long for the cursor to appear in that input text field. There is no problem with other fields which have search helps associated with them. This field with the problem is just a text field.
    Please help.
    thanks.

  • How to create a custom shape text field?

    I have a diamond shape movieClip and I need add a text Field in the same shape format.
    Now how to create a diamond shape text field?
    Please help me!
    Thanks,
    Jafy

    there's no easy way to do that in flash.  that's an advanced task.

  • Custom Metadata Text Field not working

    Hi everyone-
    I'm trying to create a Metadata layout the will be a template for all of the editors in my company.  I've created a New Schema and added a few custom text fields.  The problem is I can't add anything to the text fields, as they are greyed out and unusable (see far right in image).  Any ideas of why this might be happening?
    Thanks,
    -Mark

    Hey Jim-
    I wanted to follow up on this with you.  I ended up creating a "template" project for our filmers to use so we all log our footage the same way.  I ended up using an existing schema and adding new, custom text fields.  I did a few tests on my system and everything seemed to be working fine.  Our filmers are now on a shoot and are beginning to log their footage with our "template".  When they enter data in the custom text fields, they end up getting a crash about every 4-6 clips.  When they reload their project, none of the logged files have saved in the bin.  Any thoughts on why this is happening?  Our filmers are using the new MBP. 
    One other note.. when they enter text into the  "description" and other text fields that are not Custom Fields, everything seems to be OK.
    Your help / insight would be greatly appreciated! 
    Thanks in advance!
    -Mark

  • 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

  • Custom formatting text?

    I some documents with custom formatting in them, for example if a sentence was:
    This should be {red}color.
    Then the world "color" should be red and the {red} should not appear.
    Now my current way of doing this it though a JTextPane.
    I do something like this (currently dont have the code with me so it may not be 100% accurate):
    // Get our temp
    String temp = this.getText ( );
    // Get our pos
    int pos = temp.indexOf ( "{red}" );
    // Set the first half
    this.setText ( temp.substring ( 0, pos ) );
    // Set the second half
    this.setText ( this.getText ( ) + temp.substring ( pos + 6, temp.length ( ) - pos - 6 );
    styledDocument.setCharacterAttributes(pos, this.getText ( ).length ( ) - pow, styledDocument.getStyle ("Red" ), false);Is their any better ways to do this?
    Can I automatically do like a
    styledDocument.addReplace ( "{red}", styledDocument.getStyle ("Red" ) ); So that it will automatically know what to replace? Thanks for any help!

    Can I automatically do like a styledDocument.addReplace ( "{red}",
    styledDocument.getStyle ("Red" ) ); So that it will automatically know what to replace? No idea what you are asking. You can write you own method to do that if you want. But the StyledDocument can't do that for you.

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

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

  • Is it possible to Create a Long Text Field (more than 255 Char Long)?

    Is it possible to Create a Long Text Field (more than 255 Char Long) as like Description field in Service Request Object??
    Thanks!

    Hi
    User can only create custom Long text field (255 Charcter) . Currently system does not support custom note creation

Maybe you are looking for

  • Hard Disk Partition Error.

    good evening bro, iam tried as u mentioned n created new volume when i click finish after  finish new simple volume it showing "the operation you selected will convert the selected basic disk to dynamic disk. if u convert the disk to dynamic , u wil

  • How to get the correct sql command in oracle?

    Hi sir, i am using this query in sql that is : SELECT C.*,ISNULL(P.Comp_Name,'') + ' (' + ISNULL(P.Comp_ID,'') + ')' Parent FROM Comp_Master C LEFT JOIN Comp_Master P ON C.Parent_ID = P.Comp_ID Where C.Comp_ID='004' so i am getting in parent column v

  • Sometimes one message blocked the whole queue

    Now I am developing a MDB in weblogic to consume the TIBCO jms queue and I have deployed the MDB properly. And normally it runs ok. But sometimes there is one message in the queue that can not be consumed by the MDB .And also this message blocked the

  • 200996

    Hi I converted DAQmx assistant (coversion attached below). I get the following error: Error 200996 (DAQmx Write Wfm NChan NSamp.vi) Possible reason(s): Measurements: Data Transfer Mechanism is not set to Programmed I/O, which is the only value suppor

  • How do I remove duplicate bookmarks in Safari

    I have literally hundreds of Duplicate bookmaks in Safari. in some cases 5 or 6 for the same site. How do I remove them. Thank you.