Java JTextField adjustTextToRight(JTextField textField)

Here you can find the source of adjustTextToRight(JTextField textField)

Description

Metodo que quita los espacios que estan solo al final del texto en el jTextField entregado

License

Open Source License

Parameter

Parameter Description
textField jTextField a utilizar

Declaration


private static void adjustTextToRight(JTextField textField) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.swing.JTextField;

public class Main {
    /**/*from  w w w.  j a va 2s  .c o m*/
     * Metodo que quita los espacios que estan solo al final del texto
     * en el jTextField entregado
     * @param textField jTextField a utilizar
     */

    private static void adjustTextToRight(JTextField textField) {

        String text = textField.getText();
        String newText = "";
        boolean segmentWithoutLetters = false;

        for (int i = 0; i < text.length(); i++) {
            if (text.substring(i, text.length()).trim().isEmpty())
                segmentWithoutLetters = !segmentWithoutLetters;

            if (!segmentWithoutLetters)
                newText += text.charAt(i);
        }

        textField.setText(newText);
    }
}

Related

  1. addHighlight(JTextField label, MouseEvent mouseEvent1, MouseEvent mouseEvent2)
  2. addInputValidator(final DocumentListener inputValidator, final JTextField... textFields)
  3. addLabelTextRows(JLabel[] labels, JTextField[] textFields, GridBagLayout gridbag, Container container)
  4. addPlaceHolder(final JTextField field, final String placeHolderText)
  5. addStyle(JTextField textField, String labelName)
  6. applyDefaultProperties(final JTextField comp)
  7. AreAllTextFieldsFilled(javax.swing.JTextField[] tfs)
  8. badField(JTextField field)
  9. bindPropertyChangeListener(final JTextField field, final String name, final PropertyChangeListener listener)