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

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

The newest version!
package net.alantea.swing.text;

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

import net.alantea.liteprops.StringProperty;
import net.alantea.swing.layout.percent.PercentConstraints;
import net.alantea.swing.layout.percent.PercentLayout;

/**
 * The Class LabeledTextField.
 */
public class InstrumentedTextArea extends JPanel
{
   
   /** The Constant serialVersionUID. */
   private static final long serialVersionUID = 1L;
   
   /** The field. */
   private TextArea field;
   
   private StringProperty data = new StringProperty();
   
    /**
     * Instantiates a new labeled text field.
     */
    public InstrumentedTextArea()
    {
       super();
       setLayout(new PercentLayout());
       
       field = new TextArea();
       PercentConstraints fieldConstraints = new PercentConstraints(0, 0, 1.0, 1.0);
       JScrollPane sp = new JScrollPane(field); 
       add(sp, fieldConstraints);

       field.getDocument().addDocumentListener(new DocumentListener() {
          @Override
          public void changedUpdate(DocumentEvent e) {}
       
          @Override
          public void insertUpdate(DocumentEvent e) {
             data.set(field.getText());
          }
       
          @Override
          public void removeUpdate(DocumentEvent e)  {
             data.set(field.getText());
          }
      });
    }
    
    public StringProperty getStringProperty()
    {
       return data;
    }
    
    /**
     * Gets the text.
     *
     * @return the text
     */
    public String getText()
    {
       return data.get();
    }
    
    /**
     * Sets the text.
     *
     * @param value the new text
     */
    public void setText(String value)
    {
       field.setText(value);
    }
    
    /**
     * Gets the text field.
     *
     * @return the text field
     */
    public TextArea getTextField()
    {
       return field;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy