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

lphystudio.core.valueeditor.StringValueEditor Maven / Gradle / Ivy

The newest version!
package lphystudio.core.valueeditor;

import lphy.core.model.Value;

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

public class StringValueEditor extends JTextField {

    private Value value;

    public StringValueEditor(Value value)  {

        this.value = value;

        setText(value.value());
        setColumns(20);

        getDocument().addDocumentListener(new DocumentListener() {
            @Override
            public void insertUpdate(DocumentEvent e) {
                setValue(getText());
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                setValue(getText());

            }

            @Override
            public void changedUpdate(DocumentEvent e) {
                setValue(getText());
            }

            void setValue(String text) {
                value.setValue(text);
            }
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy