All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.alantea.swing.text.InstrumentedTextField Maven / Gradle / Ivy

package net.alantea.swing.text;

import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import net.alantea.liteprops.StringProperty;

/**
 * The Class LabeledTextField.
 */
public class InstrumentedTextField extends TextField
{
   
   /** The Constant serialVersionUID. */
   private static final long serialVersionUID = 1L;
   
   private StringProperty data = new StringProperty();
   
    /**
     * Instantiates a new labeled text field.
     */
    public InstrumentedTextField()
    {
       super();

       getDocument().addDocumentListener(new DocumentListener() {
          @Override
          public void changedUpdate(DocumentEvent e) {}
       
          @Override
          public void insertUpdate(DocumentEvent e) {
             data.set(InstrumentedTextField.super.getText());
          }
       
          @Override
          public void removeUpdate(DocumentEvent e)  {
             data.set(InstrumentedTextField.super.getText());
          }
      });
       
       data.addListener((o, v) -> {
          if (!getText().contentEquals(v))
          {
             setText(v);
          }
       });
    }
    
    public StringProperty getStringProperty()
    {
       return data;
    }
    
    /**
     * Gets the text.
     *
     * @return the text
     */
    public String getText()
    {
       return data.get();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy