Java JTextComponent removeDocumentListeners(JTextComponent component)

Here you can find the source of removeDocumentListeners(JTextComponent component)

Description

Remove all document listeners from this text component

License

Open Source License

Parameter

Parameter Description
component a parameter

Declaration

public static void removeDocumentListeners(JTextComponent component) 

Method Source Code

//package com.java2s;
/*******************************************************************************
* Copyright (c) 2012 Firestar Software, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:/*  w  w  w.  java2  s. c o m*/
*     Firestar Software, Inc. - initial API and implementation
*
* Author:
*     Sally Conway
*
*******************************************************************************/

import javax.swing.event.DocumentListener;

import javax.swing.event.UndoableEditListener;
import javax.swing.text.AbstractDocument;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;

public class Main {
    /** Remove all document listeners from this text component
     * @param component
     */
    public static void removeDocumentListeners(JTextComponent component) {
        Document document = component.getDocument();
        if (document instanceof AbstractDocument) {
            DocumentListener[] dls = ((AbstractDocument) document).getDocumentListeners();
            for (int i = 0; i < dls.length; i++) {
                ((AbstractDocument) document).removeDocumentListener(dls[i]);
            }
            UndoableEditListener[] uels = ((AbstractDocument) document).getUndoableEditListeners();
            for (int i = 0; i < uels.length; i++) {
                ((AbstractDocument) document).removeUndoableEditListener(uels[i]);
            }
        }
    }
}

Related

  1. readOnly(JTextComponent c, Component parent)
  2. refreshJTextComponent(JTextComponent textComponent)
  3. registerEvents(final JTextComponent textCmp, final String hintText)
  4. registerUpperCase(final JTextComponent textComp)
  5. removeAllHighlightsUsingPainter(final JTextComponent textComponent, final Highlighter.HighlightPainter painter)
  6. safeGetText(JTextComponent textComponent)
  7. scrollToText(JTextComponent textComponent, int startingIndex, int endingIndex)
  8. scrollToTop(JTextComponent edit1)
  9. setError(JTextComponent component, boolean error)