Last active
March 3, 2020 13:53
-
-
Save nigjo/d14a29eab90a0a55f62228c2c71ecb03 to your computer and use it in GitHub Desktop.
A DocumentListener as a functional interface. This interface aggregates all default methods of a DocumentListener to a single method. This is usefull if you don't care about the type of change in a JTextComponent.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Attribution 4.0 International (CC BY 4.0) | |
// https://creativecommons.org/licenses/by/4.0/ | |
// | |
// Original location: | |
// https://gist.github.com/nigjo/d14a29eab90a0a55f62228c2c71ecb03 | |
// | |
package com.github.gist.nigjo; | |
import javax.swing.event.DocumentEvent; | |
import javax.swing.event.DocumentListener; | |
/** | |
* A DocumentListener as a functional interface. This interface aggregates all default | |
* methods of a DocumentListener to a single method. This is usefull if you don't care | |
* about the type of change in a JTextComponent. | |
* | |
* <pre>textfield.getDocument().addDocumentListener( | |
* (SimpleDocumentListener)this::textChangeHandlerMethod);</pre> | |
* | |
* @author Jens Hofschröer | |
*/ | |
@FunctionalInterface | |
public interface SimpleDocumentListener extends DocumentListener | |
{ | |
/** | |
* Gives notification of any change of the text of the document. Check the type of the | |
* event to determinate what kind of change this was. See the default documentation of | |
* {@link DocumentListener} for event details. | |
* | |
* @param e the document event | |
*/ | |
public void textChanged(DocumentEvent e); | |
@Override | |
public default void insertUpdate(DocumentEvent e) | |
{ | |
textChanged(e); | |
} | |
@Override | |
public default void changedUpdate(DocumentEvent e) | |
{ | |
textChanged(e); | |
} | |
@Override | |
public default void removeUpdate(DocumentEvent e) | |
{ | |
textChanged(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment