23 Mart 2018 Cuma

Swing PlainDocument Sınıfı

Giriş
Şu satırı dahil ederiz.
import javax.swing.text.PlainDocument;
Açıklaması şöyle.
A text component's model is known as document and is an instance of a class that implements the Document interface. A dcoument provides these services for a text component:
- Contains text. A document stores the textual content in Element objects, which can represent any logical text structure, such as paragraphs, text that runs share styles, and so on.
- Provides support for editing text through the remove and insertString methods.
- Notifies document listeners and undoable edit listeners of changes to text
- Manages Position objects, which track a particular location within the text even as the text is modified
- Allows you to get information about the text, such as its length, and segments of the text as a string.
PlainDocument formatlama yapmaz. DefaultStyledDocument ve ondan kalıtan HTMlDocument formatlama yapar.


insertString metodu
str yeni girilen string'i verir. offs yeni string'in nereden başladığını gösterir.
N tane karakter girebilmek için şöyle yaparız.
public void insertString(int offs, String str, AttributeSet a)throws BadLocationException{
  if (str != null && (getLength() + str.length() <= maxChars)) {
    super.insertString(offs, str, a);
  }
}

Hiç yorum yok:

Yorum Gönder