com.myjavaworld.gui
Class SingleLineDocument

java.lang.Object
  extended by javax.swing.text.AbstractDocument
      extended by javax.swing.text.PlainDocument
          extended by com.myjavaworld.gui.MPlainDocument
              extended by com.myjavaworld.gui.SingleLineDocument
All Implemented Interfaces:
Serializable, Document

public class SingleLineDocument
extends MPlainDocument

An extension of PlainDocument that allows only one line of text in the document at any given time. The purpose of this class is to use it with JTextField and its extensions so that they will not allow multiple lines of text. For E.g. The javax.swing.JTextField does not work quite well when multiple lines of text is pasted in to it.

Version:
1.0
Author:
Sai Pullabhotla, psai [at] jMethods [dot] com
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.text.AbstractDocument
AbstractDocument.AbstractElement, AbstractDocument.AttributeContext, AbstractDocument.BranchElement, AbstractDocument.Content, AbstractDocument.DefaultDocumentEvent, AbstractDocument.ElementEdit, AbstractDocument.LeafElement
 
Field Summary
 
Fields inherited from class javax.swing.text.PlainDocument
lineLimitAttribute, tabSizeAttribute
 
Fields inherited from class javax.swing.text.AbstractDocument
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementName
 
Fields inherited from interface javax.swing.text.Document
StreamDescriptionProperty, TitleProperty
 
Constructor Summary
SingleLineDocument()
          Default Constructor.
 
Method Summary
 void insertString(int offset, String str, AttributeSet a)
          Inserts the given string, str at the given position, offset.
 
Methods inherited from class com.myjavaworld.gui.MPlainDocument
getCharacterCase, getMaximumLength, setCharacterCase, setMaximumLength
 
Methods inherited from class javax.swing.text.PlainDocument
createDefaultRoot, getDefaultRootElement, getParagraphElement, insertUpdate, removeUpdate
 
Methods inherited from class javax.swing.text.AbstractDocument
addDocumentListener, addUndoableEditListener, createBranchElement, createLeafElement, createPosition, dump, fireChangedUpdate, fireInsertUpdate, fireRemoveUpdate, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, getUndoableEditListeners, postRemoveUpdate, putProperty, readLock, readUnlock, remove, removeDocumentListener, removeUndoableEditListener, render, replace, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties, writeLock, writeUnlock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SingleLineDocument

public SingleLineDocument()
Default Constructor.

Method Detail

insertString

public void insertString(int offset,
                         String str,
                         AttributeSet a)
                  throws BadLocationException
Inserts the given string, str at the given position, offset. The implementation of this method ignores all the text that appears after a new line character ( \r or \n).

Specified by:
insertString in interface Document
Overrides:
insertString in class MPlainDocument
Throws:
BadLocationException


Copyright © 2000-2012 jMethods, Inc.. All Rights Reserved.